You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2008/07/07 20:01:38 UTC

svn commit: r674569 - in /incubator/qpid/trunk/qpid/java/testkit: bin/ src/main/java/org/apache/qpid/testkit/soak/

Author: rajith
Date: Mon Jul  7 11:01:37 2008
New Revision: 674569

URL: http://svn.apache.org/viewvc?rev=674569&view=rev
Log:
This is related to QPId-1161.
Modified the soak tests to print latency samples and throughput rates for every iteration.
Added run_soak_client.sh soak_report.sh as an example of how to use soak test and produce a report.
Modified other scripts to add comments.



Added:
    incubator/qpid/trunk/qpid/java/testkit/bin/run_soak_client.sh
    incubator/qpid/trunk/qpid/java/testkit/bin/soak_report.sh
Modified:
    incubator/qpid/trunk/qpid/java/testkit/bin/perf_report.sh
    incubator/qpid/trunk/qpid/java/testkit/bin/run_pub.sh
    incubator/qpid/trunk/qpid/java/testkit/bin/run_sub.sh
    incubator/qpid/trunk/qpid/java/testkit/bin/setenv.sh
    incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/BaseTest.java
    incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedConsumer.java
    incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedProducer.java
    incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/ResourceLeakTest.java
    incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleConsumer.java
    incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleProducer.java

Modified: incubator/qpid/trunk/qpid/java/testkit/bin/perf_report.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/bin/perf_report.sh?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/bin/perf_report.sh (original)
+++ incubator/qpid/trunk/qpid/java/testkit/bin/perf_report.sh Mon Jul  7 11:01:37 2008
@@ -18,9 +18,9 @@
 # under the License.
 #
 
-# Helper script to set classpath for running Qpid example classes
-# NB: You must add the Qpid client and common jars to your CLASSPATH
-# before running this script
+# This will run the 8 use cases defined below and produce
+# a report in tabular format. Refer to the documentation
+# for more details.
 
 SUB_MEM=-Xmx1024M
 PUB_MEM=-Xmx1024M

Modified: incubator/qpid/trunk/qpid/java/testkit/bin/run_pub.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/bin/run_pub.sh?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/bin/run_pub.sh (original)
+++ incubator/qpid/trunk/qpid/java/testkit/bin/run_pub.sh Mon Jul  7 11:01:37 2008
@@ -18,10 +18,6 @@
 # under the License.
 #
 
-# Helper script to set classpath for running Qpid example classes
-# NB: You must add the Qpid client and common jars to your CLASSPATH
-# before running this script
-
 . $QPID_TEST_HOME/bin/setenv.sh
 
 echo "$@"

Added: incubator/qpid/trunk/qpid/java/testkit/bin/run_soak_client.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/bin/run_soak_client.sh?rev=674569&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/bin/run_soak_client.sh (added)
+++ incubator/qpid/trunk/qpid/java/testkit/bin/run_soak_client.sh Mon Jul  7 11:01:37 2008
@@ -0,0 +1,70 @@
+#!/bin/bash
+#
+# 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.
+#
+
+# This is a sample script for a soak test on
+# linux environment.
+# This will start n of Producers processors and record their CPU and memory stats.
+# Also the Producer out will be saved to a file as well.
+
+if [ "$JAR_PATH" = "" ] ; then
+    echo "ERROR: Please set JAR_PATH to point to the Qpid libraries ...."
+    exit 1
+fi
+
+#1 PID, $2 freq, $3 count
+calc_stats(){
+
+for ((  i = 0 ;  i <= $3; i++  ))
+ do
+     cpu=`ps auxw | grep $1 | grep -v 'grep' | awk '{print $3}'`
+     mem=`pmap $1 | grep total | grep -v 'grep' | awk '{print substr($2,0,length($2)-1)}'`
+     echo $i","$mem","$cpu
+     sleep $2
+     cpu="0.0"
+     mem="0"
+ done
+ kill -9 $1
+}
+
+# Num of producer processors to start
+num=$1
+# Log frequency in seconds
+log_freq=$2
+# Num of iterations
+log_iter=$3
+
+class_name=$4
+log_file_name=`echo $class_name | cut -d. -f6`
+
+# The total time for the test is determined by the
+# log_freq * log_iter.
+
+shift 4
+CLASSPATH=`find $JAR_PATH -name '*.jar' | tr '\n' ":"`
+
+JVM_ARGS="-Xmx1500M $@"
+echo "Starting $log_file_name with the following params $JVM_ARGS"
+
+for ((  c = 1 ;  c <= $num;  c++  ))
+do
+  $JAVA_HOME/bin/java $JVM_ARGS -cp $CLASSPATH $class_name > ${log_file_name}_${c}.log &
+  pid=`jobs -l %% | awk '{print $2}'`
+  calc_stats $pid $log_freq $log_iter > ${log_file_name}_process_${c}.log &
+done

Modified: incubator/qpid/trunk/qpid/java/testkit/bin/run_sub.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/bin/run_sub.sh?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/bin/run_sub.sh (original)
+++ incubator/qpid/trunk/qpid/java/testkit/bin/run_sub.sh Mon Jul  7 11:01:37 2008
@@ -18,10 +18,6 @@
 # under the License.
 #
 
-# Helper script to set classpath for running Qpid example classes
-# NB: You must add the Qpid client and common jars to your CLASSPATH
-# before running this script
-
 . $QPID_TEST_HOME/bin/setenv.sh
 
 echo "$@"

Modified: incubator/qpid/trunk/qpid/java/testkit/bin/setenv.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/bin/setenv.sh?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/bin/setenv.sh (original)
+++ incubator/qpid/trunk/qpid/java/testkit/bin/setenv.sh Mon Jul  7 11:01:37 2008
@@ -18,9 +18,7 @@
 # under the License.
 #
 
-# Helper script to set classpath for running Qpid example classes
-# NB: You must add the Qpid client and common jars to your CLASSPATH
-# before running this script
+# Compiles the test classes and sets the CLASSPATH
 
 # check for QPID_TEST_HOME
 if [ "$QPID_TEST_HOME" = "" ] ; then

Added: incubator/qpid/trunk/qpid/java/testkit/bin/soak_report.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/bin/soak_report.sh?rev=674569&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/bin/soak_report.sh (added)
+++ incubator/qpid/trunk/qpid/java/testkit/bin/soak_report.sh Mon Jul  7 11:01:37 2008
@@ -0,0 +1,157 @@
+#!/bin/sh
+#
+# 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.
+#
+
+# Sample script to run a soak test with MultiThreadedProducer/Consumer.
+# You need to provide the log freq and no of iterations
+# Ex to run 10 hours and collect 1 second samples 
+# soak_report.sh 1 36000
+
+# This script assumes that a suitable broker instance is started.
+
+log_freq=$1
+log_iter=$2
+
+if [ "$QPID_TEST_HOME" = "" ] ; then
+    echo "ERROR: Please set QPID_TEST_HOME ...."
+    exit 1
+fi
+
+print_rates()
+{
+ cat $1 | awk '{
+ FS = ",";
+ count = 0;
+ total_latency = 0; 
+ min_latency = 9223372036854775807;
+ max_latency = 0;
+
+ total_tp = 0;
+ min_tp = 50000;
+ max_tp = 0;
+
+ while ((getline) == 1) 
+ { 
+     total_latency = total_latency + $3
+     total_tp = total_tp + $2
+
+     if ($3 > 0)
+     { 
+        min_latency = (($3 < min_latency) ? $3 : min_latency);
+        max_latency = (($3 > max_latency) ? $3 : max_latency);
+     }
+     if ($2 > 0)
+     { 
+        min_tp = (($2 < min_tp) ? $2 : min_tp);
+        max_tp = (($2 > max_tp) ? $2 : max_tp);
+     }
+
+     count =  count + 1
+ }
+
+ print "Avg Latency (ms) : " total_latency/count
+ print "Max Latency (ms) : " max_latency
+ print "Min Latency (ms) : " min_latency
+
+ print ""
+ print "Avg Throughput (msg/sec) : " total_tp/count
+ print "Max Throughput (msg/sec) : " max_tp
+ print "Min Throughput (msg/sec) : " min_tp
+
+ print ""
+ print "Total Iteratons " count
+
+ }'
+}
+
+print_system_stats()
+{
+ cat $1 | awk '{
+ FS = ",";
+ count = 0;
+ total_memory = 0;
+ min_memory = 9223372036854775807;
+ max_memory = 0;
+
+ total_cp = 0;
+ min_cp = 50000;
+ max_cp = 0;
+
+ while ((getline) == 1) 
+ { 
+     total_memory = total_memory + $2
+     total_cp = total_cp + $3
+
+     if ($2 > 0)
+     { 
+        min_memory = (($2 < min_memory) ? $2 : min_memory);
+        max_memory = (($2 > max_memory) ? $2 : max_memory);
+     }
+     if ($3 > 0)
+     { 
+        min_cp = (($3 < min_cp) ? $3 : min_cp);
+        max_cp = (($3 > max_cp) ? $3 : max_cp);
+     }
+
+     count =  count + 1
+ }
+
+ print "Avg Memory (MB) : " total_memory/(count*1024)
+ print "Max Memory (MB) : " max_memory/1024
+ print "Min Memory (MB) : " min_memory/1024
+
+ print ""
+ print "Avg CPU         : " total_cp/count
+ print "Max CPU         : " max_cp
+ print "Min CPU         : " min_cp
+
+ print ""
+ print "Total Iteratons " count
+
+ }'
+}
+
+
+cleanup()
+{
+  kill -9 `ps aux | grep soak_client | awk '{ print $2 }'`
+}
+
+print_results()
+{  
+  printf "\n======================================================= \n"
+  print_rates MultiThreadedConsumer_1.log
+  printf "\nConsumer process stats "
+  printf "\n----------------------- \n"
+  print_system_stats MultiThreadedConsumer_process_1.log
+  printf "\nProducer process stats "
+  printf "\n----------------------- \n"
+  print_system_stats MultiThreadedProducer_process_1.log
+  printf "\n------------------------------------------------------- \n"
+}
+
+trap cleanup EXIT
+
+# runs a single instance of the MultiThreadedConsumer and MultiThreadedProducer
+sh $QPID_TEST_HOME/bin/run_soak_client.sh 1 $log_freq $log_iter org.apache.qpid.testkit.soak.MultiThreadedConsumer
+sh $QPID_TEST_HOME/bin/run_soak_client.sh 1 $log_freq $log_iter org.apache.qpid.testkit.soak.MultiThreadedProducer
+
+sleep $log_iter
+
+print_results

Modified: incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/BaseTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/BaseTest.java?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/BaseTest.java (original)
+++ incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/BaseTest.java Mon Jul  7 11:01:37 2008
@@ -22,6 +22,8 @@
 
 
 import java.text.DateFormat;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
@@ -54,6 +56,7 @@
     protected AMQConnection con;
     protected Destination dest = null;
     protected DateFormat df = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss");
+    protected NumberFormat nf = new DecimalFormat("##.00");
 
     public BaseTest()
     {

Modified: incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedConsumer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedConsumer.java?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedConsumer.java (original)
+++ incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedConsumer.java Mon Jul  7 11:01:37 2008
@@ -48,6 +48,9 @@
     {
         super();
         transacted = Boolean.getBoolean("transacted");
+        // needed only to calculate throughput.
+        // If msg_count is different set it via -Dmsg_count
+        msg_count = 10;
     }
 
     /**
@@ -75,14 +78,33 @@
                             consumer.setMessageListener(new MessageListener()
                             {
 
+                                private boolean startIteration = true;
+                                private long startTime = 0;
+
                                 public void onMessage(Message m)
                                 {
                                     try
                                     {
-                                        String payload = ((TextMessage) m).getText();
-                                        if (payload.equals("End"))
+                                        long now = System.currentTimeMillis();
+                                        if (startIteration)
+                                        {
+                                            startTime = m.getJMSTimestamp();
+                                            startIteration = false;
+                                        }
+
+                                        if (m instanceof TextMessage && ((TextMessage) m).getText().equals("End"))
                                         {
-                                            System.out.println(m.getJMSMessageID() + "," + System.currentTimeMillis());
+                                            startIteration = true;
+                                            long totalIterationTime = now - startTime;
+                                            double throughput = ((double)msg_count/(double)totalIterationTime) * 1000;
+                                            long latencySample = now - m.getJMSTimestamp();
+
+                                            StringBuilder sb = new StringBuilder();
+                                            sb.append(m.getJMSMessageID()).append(",").
+                                            append(nf.format(throughput)).append(",").append(latencySample);
+
+                                            System.out.println(sb.toString());
+
                                             MessageProducer temp = session.createProducer(m.getJMSReplyTo());
                                             Message controlMsg = session.createTextMessage();
                                             temp.send(controlMsg);

Modified: incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedProducer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedProducer.java?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedProducer.java (original)
+++ incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/MultiThreadedProducer.java Mon Jul  7 11:01:37 2008
@@ -117,7 +117,6 @@
                                 }
 
                                 TextMessage m = session.createTextMessage("End");
-                                m.setJMSMessageID("ID:" + UUID.randomUUID());
                                 m.setJMSReplyTo(feedbackQueue);
                                 prod.send(m);
 
@@ -126,7 +125,7 @@
                                     session.commit();
                                 }
 
-                                System.out.println(m.getJMSMessageID() + "," + System.currentTimeMillis());
+                                System.out.println(df.format(System.currentTimeMillis()));
                                 feedbackConsumer.receive();
                                 if (transacted)
                                 {

Modified: incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/ResourceLeakTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/ResourceLeakTest.java?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/ResourceLeakTest.java (original)
+++ incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/ResourceLeakTest.java Mon Jul  7 11:01:37 2008
@@ -103,6 +103,7 @@
                       j++;
                     }
                 }
+                System.out.println(df.format(System.currentTimeMillis()));
                 Thread.sleep(connection_idle_time);
 
                 try

Modified: incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleConsumer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleConsumer.java?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleConsumer.java (original)
+++ incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleConsumer.java Mon Jul  7 11:01:37 2008
@@ -53,6 +53,9 @@
     public SimpleConsumer()
     {
         super();
+        //needed only to calculate throughput.
+        // If msg_count is different set it via -Dmsg_count
+        msg_count = 10;
     }
 
     public void test()
@@ -69,14 +72,34 @@
                 cons[i].setMessageListener(new MessageListener()
                 {
 
+                    private boolean startIteration = true;
+                    private long startTime = 0;
+
                     public void onMessage(Message m)
                     {
                         try
                         {
-                            String payload = ((TextMessage) m).getText();
-                            if (payload.equals("End"))
+                            long now = System.currentTimeMillis();
+                            if (startIteration)
+                            {
+                                startTime = m.getJMSTimestamp();
+                                startIteration = false;
+                            }
+
+                            if (m instanceof TextMessage && ((TextMessage) m).getText().equals("End"))
                             {
-                                System.out.println(m.getJMSMessageID() + "," + System.currentTimeMillis());
+
+                                long totalIterationTime = now - startTime;
+                                startIteration = true;
+                                double throughput = ((double)msg_count/(double)totalIterationTime) * 1000;
+                                long latencySample = now - m.getJMSTimestamp();
+
+                                StringBuilder sb = new StringBuilder();
+                                sb.append(m.getJMSMessageID()).append(",").
+                                append(nf.format(throughput)).append(",").append(latencySample);
+
+                                System.out.println(sb.toString());
+
                                 MessageProducer temp = sessions[0].createProducer(m.getJMSReplyTo());
                                 Message controlMsg = sessions[0].createTextMessage();
                                 temp.send(controlMsg);

Modified: incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleProducer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleProducer.java?rev=674569&r1=674568&r2=674569&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleProducer.java (original)
+++ incubator/qpid/trunk/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/soak/SimpleProducer.java Mon Jul  7 11:01:37 2008
@@ -109,7 +109,7 @@
                 for (int i = 0; i < msg_count - 1; i++)
                 {
                     Message msg = getNextMessage();
-                    msg.setJMSMessageID("ID:" + UUID.randomUUID());
+                    msg.setJMSTimestamp(System.currentTimeMillis());
                     prods[prod_pointer].send(msg);
                     if (multi_session)
                     {
@@ -122,10 +122,9 @@
                 }
 
                 TextMessage m = sessions[0].createTextMessage("End");
-                m.setJMSMessageID("ID:" + UUID.randomUUID());
                 m.setJMSReplyTo(feedbackQueue);
                 prods[prod_pointer].send(m);
-                System.out.println(m.getJMSMessageID() + "," + System.currentTimeMillis());
+                System.out.println(df.format(System.currentTimeMillis()));
                 feedbackConsumer.receive();
                 Thread.sleep(1000);
             }