activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r674866 - in /activemq/trunk/activemq-protocol-buffer/src: main/java/org/apache/activemq/protocolbuffer/ main/proto/ test/java/org/apache/activemq/protocolbuffer/
Date Tue, 08 Jul 2008 16:07:53 GMT
Author: jstrachan
Date: Tue Jul  8 09:07:52 2008
New Revision: 674866

URL: http://svn.apache.org/viewvc?rev=674866&view=rev
Log:
added a like for like comparision of OpenWire versus PB (see Performance2Test)

Added:
    activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/OpenWirePerformanceTest.java
      - copied, changed from r674845, activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java
    activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/StopWatch.java
  (with props)
    activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/TestSupport.java
  (with props)
Modified:
    activemq/trunk/activemq-protocol-buffer/src/main/java/org/apache/activemq/protocolbuffer/OpenWire.java
    activemq/trunk/activemq-protocol-buffer/src/main/proto/openwire.proto
    activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java

Modified: activemq/trunk/activemq-protocol-buffer/src/main/java/org/apache/activemq/protocolbuffer/OpenWire.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-protocol-buffer/src/main/java/org/apache/activemq/protocolbuffer/OpenWire.java?rev=674866&r1=674865&r2=674866&view=diff
==============================================================================
--- activemq/trunk/activemq-protocol-buffer/src/main/java/org/apache/activemq/protocolbuffer/OpenWire.java
(original)
+++ activemq/trunk/activemq-protocol-buffer/src/main/java/org/apache/activemq/protocolbuffer/OpenWire.java
Tue Jul  8 09:07:52 2008
@@ -51,8 +51,8 @@
       "he.activemq.protocolbuffer.ShortProperty" +
       "\022G\n\rbyte_property\030\010 \003(\01320.org.apache.act" +
       "ivemq.protocolbuffer.ByteProperty\"\306\006\n\007Me" +
-      "ssage\022\023\n\013producer_id\030\001 \002(\005\022\030\n\020producer_c" +
-      "ounter\030\002 \002(\005\022D\n\013destination\030\003 \002(\0132/.org." +
+      "ssage\022\023\n\013producer_id\030\001 \001(\005\022\030\n\020producer_c" +
+      "ounter\030\002 \001(\005\022D\n\013destination\030\003 \002(\0132/.org." +
       "apache.activemq.protocolbuffer.Destinati" +
       "on\022M\n\024original_destination\030\004 \001(\0132/.org.a" +
       "pache.activemq.protocolbuffer.Destinatio" +
@@ -4464,13 +4464,13 @@
       return org.apache.activemq.protocolbuffer.OpenWire.internal_static_org_apache_activemq_protocolbuffer_Message_fieldAccessorTable;
     }
     
-    // required int32 producer_id = 1;
+    // optional int32 producer_id = 1;
     private boolean hasProducerId;
     private int producerId_ = 0;
     public boolean hasProducerId() { return hasProducerId; }
     public int getProducerId() { return producerId_; }
     
-    // required int32 producer_counter = 2;
+    // optional int32 producer_counter = 2;
     private boolean hasProducerCounter;
     private int producerCounter_ = 0;
     public boolean hasProducerCounter() { return hasProducerCounter; }
@@ -4631,8 +4631,6 @@
     public int getGroupSequence() { return groupSequence_; }
     
     public final boolean isInitialized() {
-      if (!hasProducerId) return false;
-      if (!hasProducerCounter) return false;
       if (!hasDestination) return false;
       if (!getDestination().isInitialized()) return false;
       if (hasOriginalDestination()) {
@@ -5222,7 +5220,7 @@
       }
       
       
-      // required int32 producer_id = 1;
+      // optional int32 producer_id = 1;
       public boolean hasProducerId() {
         return result.hasProducerId();
       }
@@ -5240,7 +5238,7 @@
         return this;
       }
       
-      // required int32 producer_counter = 2;
+      // optional int32 producer_counter = 2;
       public boolean hasProducerCounter() {
         return result.hasProducerCounter();
       }

Modified: activemq/trunk/activemq-protocol-buffer/src/main/proto/openwire.proto
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-protocol-buffer/src/main/proto/openwire.proto?rev=674866&r1=674865&r2=674866&view=diff
==============================================================================
--- activemq/trunk/activemq-protocol-buffer/src/main/proto/openwire.proto (original)
+++ activemq/trunk/activemq-protocol-buffer/src/main/proto/openwire.proto Tue Jul  8 09:07:52
2008
@@ -96,8 +96,9 @@
 
 // Message
 message Message {
-  required int32 producer_id = 1;
-  required int32 producer_counter = 2;
+  // TODO these should be required
+  optional int32 producer_id = 1;
+  optional int32 producer_counter = 2;
 
   // TODO no messageID?
   

Copied: activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/OpenWirePerformanceTest.java
(from r674845, activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/OpenWirePerformanceTest.java?p2=activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/OpenWirePerformanceTest.java&p1=activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java&r1=674845&r2=674866&rev=674866&view=diff
==============================================================================
--- activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java
(original)
+++ activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/OpenWirePerformanceTest.java
Tue Jul  8 09:07:52 2008
@@ -17,54 +17,92 @@
  */
 package org.apache.activemq.protocolbuffer;
 
-import com.google.protobuf.CodedInputStream;
-import com.google.protobuf.CodedOutputStream;
-import junit.framework.TestCase;
+import org.apache.activemq.command.*;
+import org.apache.activemq.openwire.OpenWireFormat;
 
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.*;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class Performance2Test extends TestCase {
-    protected int messageCount = 10;
-    protected String fileName = "target/messages2.openwire";
+public class OpenWirePerformanceTest extends TestSupport {
 
+    protected String fileName = "target/messages3.openwire";
+    protected OpenWireFormat openWireFormat = createOpenWireFormat();
+    protected ActiveMQDestination destination = new ActiveMQQueue("FOO.BAR");
+    protected ProducerId producerId = new ProducerId(new SessionId(new ConnectionId("abc"),
1), 1);
 
     public void testPerformance() throws Exception {
-        FileOutputStream out = new FileOutputStream(fileName);
-        OpenWire.Destination destination = OpenWire.Destination.newBuilder().setName("FOO.BAR").setType(OpenWire.Destination.DestinationType.QUEUE).build();
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
+        DataOutputStream ds = new DataOutputStream(out);
 
+        StopWatch watch = createStopWatch("writer");
         for (int i = 0; i < messageCount; i++) {
-            OpenWire.Message message = OpenWire.Message.newBuilder()
-                    .setDestination(destination)
-                    .setPersistent(true)
-                    .setProducerId(1234)
-                    .setProducerCounter(i)
-                    .setType("type:" + i)
-                    .build();
+            watch.start();
+            Message message = new ActiveMQMessage();
 
-            System.out.println("Writing message: " + i + " = " + message);
+            message.setDestination(destination);
+            message.setPersistent(true);
+            message.setType("type:" + i);
+            message.setCorrelationId("ABCD");
+
+            if (useProducerId) {
+                message.setProducerId(producerId);
+                message.setMessageId(new MessageId(producerId, i));
+            }
+
+            if (verbose) {
+                System.out.println("Writing message: " + i + " = " + message);
+            }
+/*
             byte[] bytes = message.toByteArray();
             int size = bytes.length;
             out.write(size);
-            System.out.println("writing bytes: " + size);
+            //System.out.println("writing bytes: " + size);
             out.write(bytes);
+*/
+
+            openWireFormat.marshal(message, ds);
+            watch.stop();
         }
         out.flush();
         out.close();
 
         // now lets try read them!
-        FileInputStream in = new FileInputStream(fileName);
+        StopWatch watch2 = createStopWatch("reader");
+        InputStream in = new BufferedInputStream(new FileInputStream(fileName));
+        DataInput dis = new DataInputStream(in);
+
         for (int i = 0; i < messageCount; i++) {
+            watch2.start();
+
+            Object message = openWireFormat.unmarshal(dis);
+/*
             int size = in.read();
             byte[] data = new byte[size];
             in.read(data);
-            OpenWire.Message message = OpenWire.Message.parseFrom(data);
-            System.out.println("Reading message: " + i + " = " + message);
+*/
+            if (verbose) {
+                System.out.println("Reading message: " + i + " = " + message);
+            }
+            watch2.stop();
         }
         in.close();
     }
 
+    private StopWatch createStopWatch(String name) {
+        StopWatch answer = new StopWatch(name);
+        answer.setLogFrequency(messageCount / 10);
+        return answer;
+    }
+
+
+    protected OpenWireFormat createOpenWireFormat() {
+        OpenWireFormat wf = new OpenWireFormat();
+        wf.setCacheEnabled(true);
+        wf.setStackTraceEnabled(false);
+        wf.setVersion(OpenWireFormat.DEFAULT_VERSION);
+        return wf;
+    }
+
 }
\ No newline at end of file

Modified: activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java?rev=674866&r1=674865&r2=674866&view=diff
==============================================================================
--- activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java
(original)
+++ activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/Performance2Test.java
Tue Jul  8 09:07:52 2008
@@ -17,54 +17,70 @@
  */
 package org.apache.activemq.protocolbuffer;
 
-import com.google.protobuf.CodedInputStream;
-import com.google.protobuf.CodedOutputStream;
-import junit.framework.TestCase;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.*;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class Performance2Test extends TestCase {
-    protected int messageCount = 10;
-    protected String fileName = "target/messages2.openwire";
+public class Performance2Test extends TestSupport {
 
+    protected String fileName = "target/messages2.openwire";
+    protected OpenWire.Destination destination = OpenWire.Destination.newBuilder().setName("FOO.BAR").setType(OpenWire.Destination.DestinationType.QUEUE).build();
 
     public void testPerformance() throws Exception {
-        FileOutputStream out = new FileOutputStream(fileName);
-        OpenWire.Destination destination = OpenWire.Destination.newBuilder().setName("FOO.BAR").setType(OpenWire.Destination.DestinationType.QUEUE).build();
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
 
+        StopWatch watch = createStopWatch("writer");
         for (int i = 0; i < messageCount; i++) {
-            OpenWire.Message message = OpenWire.Message.newBuilder()
+            watch.start();
+            OpenWire.Message.Builder builder = OpenWire.Message.newBuilder()
                     .setDestination(destination)
                     .setPersistent(true)
-                    .setProducerId(1234)
-                    .setProducerCounter(i)
                     .setType("type:" + i)
-                    .build();
+                    .setCorrelationId("ABCD");
 
-            System.out.println("Writing message: " + i + " = " + message);
+            if (useProducerId) {
+                builder = builder.setProducerId(1234)
+                        .setProducerCounter(i);
+            }
+
+            OpenWire.Message message = builder.build();
+
+            if (verbose) {
+                System.out.println("Writing message: " + i + " = " + message);
+            }
             byte[] bytes = message.toByteArray();
             int size = bytes.length;
             out.write(size);
-            System.out.println("writing bytes: " + size);
+            //System.out.println("writing bytes: " + size);
             out.write(bytes);
+            watch.stop();
         }
         out.flush();
         out.close();
 
         // now lets try read them!
-        FileInputStream in = new FileInputStream(fileName);
+        StopWatch watch2 = createStopWatch("reader");
+        InputStream in = new BufferedInputStream(new FileInputStream(fileName));
         for (int i = 0; i < messageCount; i++) {
+            watch2.start();
+
             int size = in.read();
             byte[] data = new byte[size];
             in.read(data);
             OpenWire.Message message = OpenWire.Message.parseFrom(data);
-            System.out.println("Reading message: " + i + " = " + message);
+            if (verbose) {
+                System.out.println("Reading message: " + i + " = " + message);
+            }
+            watch2.stop();
         }
         in.close();
     }
 
+    private StopWatch createStopWatch(String name) {
+        StopWatch answer = new StopWatch(name);
+        answer.setLogFrequency(messageCount / 10);
+        return answer;
+    }
+
 }
\ No newline at end of file

Added: activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/StopWatch.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/StopWatch.java?rev=674866&view=auto
==============================================================================
--- activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/StopWatch.java
(added)
+++ activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/StopWatch.java
Tue Jul  8 09:07:52 2008
@@ -0,0 +1,111 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.protocolbuffer;
+
+import java.text.NumberFormat;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class StopWatch {
+    private final String id;
+    private int loopCount;
+    private int totalLoops;
+    private long groupElapsed;
+    private long totalElapsed;
+    private long startTime;
+    private long minTime = Long.MAX_VALUE;
+    private long maxTime = Long.MIN_VALUE;
+    private int logFrequency = 1000;
+    private NumberFormat numberFormat = NumberFormat.getNumberInstance();
+
+    public StopWatch(String id) {
+        this.id = id;
+    }
+
+    public void start() {
+        startTime = System.currentTimeMillis();
+    }
+
+    public void stop() {
+        long elapsedTime = System.currentTimeMillis() - startTime;
+        groupElapsed += elapsedTime;
+        totalElapsed += elapsedTime;
+        loopCount++;
+        totalLoops++;
+
+        if (elapsedTime > maxTime) {
+            maxTime = elapsedTime;
+        }
+        if (elapsedTime < minTime) {
+            minTime = elapsedTime;
+        }
+        if (logFrequency > 0 && loopCount % logFrequency == 0) {
+            System.out.println(toString());
+            reset();
+        }
+    }
+
+    protected void reset() {
+        loopCount = 0;
+        groupElapsed = 0;
+        minTime = Long.MAX_VALUE;
+        maxTime = Long.MIN_VALUE;
+    }
+
+    @Override
+    public String toString() {
+        double average = totalElapsed;
+        average *= logFrequency;
+        average /= totalLoops;
+        //average /= 1000;
+        return id + " count: " + loopCount + " elapsed: " + groupElapsed + " min: " + minTime
+ " max: " + maxTime + " average: " + formatSeconds(average);
+    }
+
+    public int getLogFrequency() {
+        return logFrequency;
+    }
+
+    public void setLogFrequency(int logFrequency) {
+        this.logFrequency = logFrequency;
+    }
+
+    public int getLoopCount() {
+        return loopCount;
+    }
+
+    public long getMaxTime() {
+        return maxTime;
+    }
+
+    public long getMinTime() {
+        return minTime;
+    }
+
+    public long getStartTime() {
+        return startTime;
+    }
+
+    public long getGroupElapsed() {
+        return groupElapsed;
+    }
+
+    protected String formatSeconds(double time) {
+        return numberFormat.format(time);
+    }
+}

Propchange: activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/StopWatch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/TestSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/TestSupport.java?rev=674866&view=auto
==============================================================================
--- activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/TestSupport.java
(added)
+++ activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/TestSupport.java
Tue Jul  8 09:07:52 2008
@@ -0,0 +1,29 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.protocolbuffer;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class TestSupport extends TestCase {
+    protected int messageCount = 10000000;
+    protected boolean verbose = false;
+    protected boolean useProducerId = false;
+}

Propchange: activemq/trunk/activemq-protocol-buffer/src/test/java/org/apache/activemq/protocolbuffer/TestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message