[omniORB] performance problem increasing sequence length in a loop

Arne Pajunen arne.pajunen at openttcn.fi
Wed Nov 19 11:46:03 GMT 2008



Duncan Grisby wrote:
> On Thursday 6 November, Michael Teske wrote:
> 
>> We're trying (again) to port our system from Orbacus to
>> omniORB. Unfortunately we have lots of code where sequences are
>> resized dynamically, sometimes even in a loop (I know this is not the
>> best style, but to find all these locations could become a nightmare).
>>
>> While something like this is very fast in Orbacus it becomes very slow
>> in omniORB.  I think this isbecause Orbcaus doubles the reserved
>> buffer if the new desired length is lower than the old length * 2,
>> while omniORB just allocates the new length and copies the old
>> sequence over *every* time.
> 
> You're right -- omniORB does not currently increase sequence buffers in
> an incremental way, so code that repeatedly increases the length by one
> will be O(n^2).
> 
> I'd welcome patches that implement a more efficient growth scheme. Make
> sure your patches follow the existing code style.
> 
> Cheers,
> 
> Duncan.
> 

Hi,

We actually noticed almost the exact same issue in our system after 
porting it from Orbacus to omniORB. I wrote a small patch that changes 
the allocator for the common sequence base types to double the old 
length until sufficient for new desired length.

I'm not sure if this is good enough for inclusion in the main omniORB 
tree, since its not the best possible allocation scheme. Its also not 
configurable and i didn't look too hard if I caught all the cases where 
the allocated buffer is resized, but some might find it a useful 
workaround for the issue. It fixed the performance issues we were 
experiencing.

If someone wants to make a cleaner patch based on this, you're more than 
welcome to do so. I would be most interested in a permanent fix.

Best regards,

Arne Pajunen
Software Developer
OpenTTCN Oy, Finland
-------------- next part --------------
diff -ru omniORB-4.1.3-clean/include/omniORB4/seqTemplatedecls.h omniORB-4.1.3/include/omniORB4/seqTemplatedecls.h
--- omniORB-4.1.3-clean/include/omniORB4/seqTemplatedecls.h	2006-04-28 21:40:46.000000000 +0300
+++ omniORB-4.1.3/include/omniORB4/seqTemplatedecls.h	2008-11-14 18:31:57.297326400 +0200
@@ -155,7 +155,11 @@
       // Allocate buffer on-demand. Either pd_data == 0 
       //                            or pd_data = buffer for pd_max elements
       if (!pd_buf || len > pd_max) {
-	copybuffer(((len > pd_max) ? len : pd_max));
+          _CORBA_ULong new_length = (pd_max == 0 ? len : pd_max);
+          if (len > new_length) {
+              while (new_length < len) new_length = new_length*2;
+          }
+	      copybuffer(new_length);
       }
     }
     pd_len = len;
@@ -1109,7 +1113,11 @@
       // Allocate buffer on-demand. Either pd_data == 0 
       //                            or pd_data = buffer for pd_max elements
       if (!pd_buf || len > pd_max) {
-	copybuffer(((len > pd_max) ? len : pd_max));
+          _CORBA_ULong new_length = (pd_max == 0 ? len : pd_max);
+          if (len > new_length) {
+              while (new_length < len) new_length = new_length*2;
+          }
+	      copybuffer(new_length);
       }
     }
 
@@ -1899,7 +1907,11 @@
       // Allocate buffer on-demand. Either pd_data == 0 
       //                            or pd_data = buffer for pd_max elements
       if (!pd_data || len > pd_max) {
-	copybuffer(((len > pd_max) ? len : pd_max));
+          _CORBA_ULong new_length = (pd_max == 0 ? len : pd_max);
+          if (len > new_length) {
+              while (new_length < len) new_length = new_length*2;
+          }
+	      copybuffer(new_length);
       }
     }
 
diff -ru omniORB-4.1.3-clean/include/omniORB4/stringtypes.h omniORB-4.1.3/include/omniORB4/stringtypes.h
--- omniORB-4.1.3-clean/include/omniORB4/stringtypes.h	2005-11-17 19:03:27.000000000 +0200
+++ omniORB-4.1.3/include/omniORB4/stringtypes.h	2008-11-14 18:31:29.950526400 +0200
@@ -634,7 +634,11 @@
       // Allocate buffer on-demand. Either pd_data == 0 
       //                            or pd_data = buffer for pd_max elements
       if (!pd_data || len > pd_max) {
-	copybuffer(((len > pd_max) ? len : pd_max));
+          _CORBA_ULong new_length = (pd_max == 0 ? len : pd_max);
+          if (len > new_length) {
+              while (new_length < len) new_length = new_length*2;
+          }
+	      copybuffer(new_length);
       }
     }
     pd_len = len;
diff -ru omniORB-4.1.3-clean/include/omniORB4/valueTemplatedecls.h omniORB-4.1.3/include/omniORB4/valueTemplatedecls.h
--- omniORB-4.1.3-clean/include/omniORB4/valueTemplatedecls.h	2007-04-19 01:32:43.000000000 +0300
+++ omniORB-4.1.3/include/omniORB4/valueTemplatedecls.h	2008-11-14 18:31:38.748926400 +0200
@@ -467,7 +467,11 @@
       // Allocate buffer on-demand. Either pd_data == 0 
       //                            or pd_data = buffer for pd_max elements
       if (!pd_data || len > pd_max) {
-	copybuffer(((len > pd_max) ? len : pd_max));
+          _CORBA_ULong new_length = (pd_max == 0 ? len : pd_max);
+          if (len > new_length) {
+              while (new_length < len) new_length = new_length*2;
+          }
+	      copybuffer(new_length);
       }
     }
 
diff -ru omniORB-4.1.3-clean/include/omniORB4/wstringtypes.h omniORB-4.1.3/include/omniORB4/wstringtypes.h
--- omniORB-4.1.3-clean/include/omniORB4/wstringtypes.h	2005-11-17 19:03:27.000000000 +0200
+++ omniORB-4.1.3/include/omniORB4/wstringtypes.h	2008-11-14 18:31:45.940526400 +0200
@@ -610,7 +610,11 @@
       // Allocate buffer on-demand. Either pd_data == 0 
       //                            or pd_data = buffer for pd_max elements
       if (!pd_data || len > pd_max) {
-	copybuffer(((len > pd_max) ? len : pd_max));
+          _CORBA_ULong new_length = (pd_max == 0 ? len : pd_max);
+          if (len > new_length) {
+              while (new_length < len) new_length = new_length*2;
+          }
+	      copybuffer(new_length);
       }
     }
     pd_len = len;


More information about the omniORB-list mailing list