You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2006/05/19 01:48:15 UTC

svn commit: r407665 - in /tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes: group/interceptors/ThroughputInterceptor.java io/ChannelData.java io/XByteBuffer.java

Author: fhanik
Date: Thu May 18 16:48:15 2006
New Revision: 407665

URL: http://svn.apache.org/viewvc?rev=407665&view=rev
Log:
Small performance improvements

Modified:
    tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/ThroughputInterceptor.java
    tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/ChannelData.java
    tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/XByteBuffer.java

Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/ThroughputInterceptor.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/ThroughputInterceptor.java?rev=407665&r1=407664&r2=407665&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/ThroughputInterceptor.java (original)
+++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/ThroughputInterceptor.java Thu May 18 16:48:15 2006
@@ -79,7 +79,7 @@
     }
 
     public void messageReceived(ChannelMessage msg) {
-        long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackage().length);
+        long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackageLength());
         mbRx += ((double)bytes)/(1024d*1024d);
         if ( msgRxCnt.get() % interval == 0 ) report(timeTx);
         msgRxCnt.addAndGet(1);

Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/ChannelData.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/ChannelData.java?rev=407665&r1=407664&r2=407665&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/ChannelData.java (original)
+++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/ChannelData.java Thu May 18 16:48:15 2006
@@ -183,12 +183,16 @@
      * @return byte[]
      */
     public byte[] getDataPackage()  {
-        byte[] addr = ((MemberImpl)address).getData(false);
         int length = getDataPackageLength();
         byte[] data = new byte[length];
         int offset = 0;
+        return getDataPackage(data,offset);
+    }
+
+    public byte[] getDataPackage(byte[] data, int offset)  {
+        byte[] addr = ((MemberImpl)address).getData(false);
         XByteBuffer.toBytes(options,data,offset);
-        offset = 4; //options
+        offset += 4; //options
         XByteBuffer.toBytes(timestamp,data,offset);
         offset += 8; //timestamp
         XByteBuffer.toBytes(uniqueId.length,data,offset);

Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/XByteBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/XByteBuffer.java?rev=407665&r1=407664&r2=407665&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/XByteBuffer.java (original)
+++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/io/XByteBuffer.java Thu May 18 16:48:15 2006
@@ -332,13 +332,39 @@
      * Creates a complete data package
      * @param indata - the message data to be contained within the package
      * @param compressed - compression flag for the indata buffer
-     * @return - a full package (header,compress,size,data,footer)
+     * @return - a full package (header,size,data,footer)
      * 
      */
     public static byte[] createDataPackage(ChannelData cdata) {
-        return createDataPackage(cdata.getDataPackage());
+//        return createDataPackage(cdata.getDataPackage());
+        //avoid one extra byte array creation
+        int dlength = cdata.getDataPackageLength();
+        int length = getDataPackageLength(dlength);
+        byte[] data = new byte[length];
+        int offset = 0;
+        System.arraycopy(START_DATA, 0, data, offset, START_DATA.length);
+        offset += START_DATA.length;
+        toBytes(dlength,data, START_DATA.length);
+        offset += 4;
+        cdata.getDataPackage(data,offset);
+        offset += dlength;
+        System.arraycopy(END_DATA, 0, data, offset, END_DATA.length);
+        offset += END_DATA.length;
+        return data;
     }
     
+    public static byte[] createDataPackage(byte[] data, int doff, int dlength, byte[] buffer, int bufoff) {
+        if ( (buffer.length-bufoff) > getDataPackageLength(dlength) ) {
+            throw new ArrayIndexOutOfBoundsException("Unable to create data package, buffer is too small.");
+        }
+        System.arraycopy(START_DATA, 0, buffer, bufoff, START_DATA.length);
+        toBytes(data.length,buffer, bufoff+START_DATA.length);
+        System.arraycopy(data, doff, buffer, bufoff+START_DATA.length + 4, dlength);
+        System.arraycopy(END_DATA, 0, buffer, bufoff+START_DATA.length + 4 + data.length, END_DATA.length);
+        return buffer;
+    }
+
+    
     public static int getDataPackageLength(int datalength) {
         int length = 
             START_DATA.length + //header length
@@ -355,22 +381,13 @@
         return createDataPackage(data,0,data.length,result,0);
     }
     
-    public static byte[] createDataPackage(byte[] data, int doff, int dlength, byte[] buffer, int bufoff) {
-        if ( (buffer.length-bufoff) > getDataPackageLength(dlength) ) {
-            throw new ArrayIndexOutOfBoundsException("Unable to create data package, buffer is too small.");
-        }
-        System.arraycopy(START_DATA, 0, buffer, bufoff, START_DATA.length);
-        toBytes(data.length,buffer, bufoff+START_DATA.length);
-        System.arraycopy(data, doff, buffer, bufoff+START_DATA.length + 4, dlength);
-        System.arraycopy(END_DATA, 0, buffer, bufoff+START_DATA.length + 4 + data.length, END_DATA.length);
-        return buffer;
-    }
+    
 
-    public static void fillDataPackage(byte[] data, int doff, int dlength, XByteBuffer buf) {
-        int pkglen = getDataPackageLength(dlength);
-        if ( buf.getCapacity() <  pkglen ) buf.expand(pkglen);
-        createDataPackage(data,doff,dlength,buf.getBytesDirect(),buf.getLength());
-    }
+//    public static void fillDataPackage(byte[] data, int doff, int dlength, XByteBuffer buf) {
+//        int pkglen = getDataPackageLength(dlength);
+//        if ( buf.getCapacity() <  pkglen ) buf.expand(pkglen);
+//        createDataPackage(data,doff,dlength,buf.getBytesDirect(),buf.getLength());
+//    }
 
     /**
      * Convert four bytes to an int



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org