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

svn commit: r689166 - in /incubator/qpid/trunk/qpid/cpp/src/tests: consume.cpp perfdist publish.cpp start_cluster_hosts

Author: aconway
Date: Tue Aug 26 11:35:00 2008
New Revision: 689166

URL: http://svn.apache.org/viewvc?rev=689166&view=rev
Log:
Test improvements.
 - print rates for publish, consume
 - consistent use of -s for spreadsheet-friendly output.
 - start_cluster_hosts to start multi-host cluster via ssh.

Added:
    incubator/qpid/trunk/qpid/cpp/src/tests/start_cluster_hosts   (with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/src/tests/consume.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/perfdist
    incubator/qpid/trunk/qpid/cpp/src/tests/publish.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/consume.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/consume.cpp?rev=689166&r1=689165&r2=689166&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/consume.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/consume.cpp Tue Aug 26 11:35:00 2008
@@ -34,23 +34,26 @@
 using namespace qpid;
 using namespace qpid::client;
 using namespace qpid::sys;
-using std::string;
+using namespace std;
 
-typedef std::vector<std::string> StringSet;
+typedef vector<string> StringSet;
 
 struct Args : public qpid::TestOptions {
     uint count;
     uint ack;
     string queue;
     bool declare;
+    bool summary;
     
-    Args() : count(0), ack(1)
+    Args() : count(1000), ack(0), queue("publish-consume"),
+             declare(false), summary(false)
     {
         addOptions()
             ("count", optValue(count, "N"), "number of messages to publish")
             ("ack-frequency", optValue(ack, "N"), "ack every N messages (0 means use no-ack mode)")
             ("queue", optValue(queue, "<queue name>"), "queue to consume from")
-            ("declare", optValue(declare), "declare the queue");
+            ("declare", optValue(declare), "declare the queue")
+            ("s,summary", optValue(summary), "Print undecorated rate.");
     }
 };
 
@@ -78,12 +81,17 @@
                             false);
         subs.subscribe(lq, opts.queue);
         Message msg;
+        AbsTime begin=now();        
         for (size_t i = 0; i < opts.count; ++i) {
             msg=lq.pop();
             QPID_LOG(info, "Received: " << msg.getMessageProperties().getCorrelationId());
         }
         if (opts.ack != 0)
             subs.getAckPolicy().ackOutstanding(session); // Cumulative ack for final batch.
+        AbsTime end=now();
+        double secs(double(Duration(begin,end))/TIME_SEC);
+        if (opts.summary) cout << opts.count/secs << endl;
+        else cout << "Time: " << secs << "s Rate: " << opts.count/secs << endl;
     }
 
     ~Client() 
@@ -91,8 +99,8 @@
         try{
             session.close();
             connection.close();
-        } catch(const std::exception& e) {
-            std::cout << e.what() << std::endl;
+        } catch(const exception& e) {
+            cout << e.what() << endl;
         }
     }
 };
@@ -104,8 +112,8 @@
         Client client;
         client.consume();
         return 0;
-    } catch(const std::exception& e) {
-	std::cout << e.what() << std::endl;
+    } catch(const exception& e) {
+	cout << e.what() << endl;
     }
     return 1;
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/perfdist
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/perfdist?rev=689166&r1=689165&r2=689166&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/perfdist (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/perfdist Tue Aug 26 11:35:00 2008
@@ -33,16 +33,24 @@
 	--publish|--subscribe|--setup|--control) usage "Don't pass perftest action flags: $1" ;;
 	--npubs) collect $1 $2; NPUBS=$2; shift 2 ;;
 	--nsubs) collect $1 $2; NSUBS=$2; shift 2 ;;
+	-s|--summary) collect $1; QUIET=yes; shift 1 ;;
 	--) COLLECT=HOSTS; shift ;; 
 	*) collect $1; shift ;;
     esac
 done
+
 if [ -z "$HOSTS" ]; then usage "No hosts listed after --"; fi
-PATH="`dirname $0`:$PATH"	
-PERFTEST="`which perftest` $ARGS" || usage "Can't find perftest executable"
+ADDPATH="$PWD"
+PATH=$ADDPATH:$PATH
+which perftest>/dev/null || exit 1
+PERFTEST="perftest $ARGS"
 
 HOSTS=($HOSTS)
-start() { ssh ${HOSTS[i % ${#HOSTS[*]}]} $PERFTEST $*& }
+start() {
+    HOST=${HOSTS[i % ${#HOSTS[*]}]}
+    test -z "$QUIET" && echo "Client $i on $HOST $*"
+    ssh -fT $HOST "PATH=$ADDPATH:\$PATH" $PERFTEST "$@"
+}
 
 $PERFTEST --setup
 for (( i=0 ; i < $NPUBS ; ++i)); do start --publish; done

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/publish.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/publish.cpp?rev=689166&r1=689165&r2=689166&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/publish.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/publish.cpp Tue Aug 26 11:35:00 2008
@@ -34,9 +34,9 @@
 using namespace qpid;
 using namespace qpid::client;
 using namespace qpid::sys;
-using std::string;
+using namespace std;
 
-typedef std::vector<std::string> StringSet;
+typedef vector<string> StringSet;
 
 struct Args : public qpid::TestOptions {
     uint size;
@@ -44,15 +44,18 @@
     bool durable;
     string destination;
     string routingKey;
+    bool summary;
+    bool id;
 
-    Args() : size(256), count(1000), durable(true)
-    {
+    Args() : size(256), count(1000), durable(true), routingKey("publish-consume"), summary(false), id(false) {
         addOptions()
             ("size", optValue(size, "N"), "message size")
             ("count", optValue(count, "N"), "number of messages to publish")
             ("durable", optValue(durable, "yes|no"), "use durable messages")
             ("destination", optValue(destination, "<exchange name>"), "destination to publish to")
-            ("routing-key", optValue(routingKey, "<key>"), "routing key to publish with");
+            ("routing-key", optValue(routingKey, "<key>"), "routing key to publish with")
+            ("summary,s", optValue(summary), "Output only the rate.")
+            ("id", optValue(id), "Add unique correlation ID");
     }
 };
 
@@ -69,26 +72,35 @@
         session = connection.newSession();
     }
 
-    std::string id(uint i)
-    {
-        std::stringstream s;
-        s << "msg" << i;
-        return s.str();
+    // Cheap hex calculation, avoid expensive ostrstream and string
+    // creation to generate correlation ids in message loop.
+    char hex(char i) { return i<10 ? '0'+i : 'A'+i-10; }
+    void hex(char i, string& s) { 
+        s[0]=hex(i>>24); s[1]=hex(i>>16); s[2]=hex(i>>8); s[3]=i;
     }
 
     void publish()
     {
+        AbsTime begin=now();
         Message msg(string(opts.size, 'X'), opts.routingKey);
+        string correlationId = "0000";
         if (opts.durable)
             msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT);
         
         for (uint i = 0; i < opts.count; i++) {
-            msg.getMessageProperties().setCorrelationId(id(i + 1));
+            if (opts.id) {
+                hex(i+1, correlationId);
+                msg.getMessageProperties().setCorrelationId(correlationId);
+            }
             session.messageTransfer(arg::destination=opts.destination,
                                     arg::content=msg,
                                     arg::acceptMode=1);
         }
         session.sync();
+        AbsTime end=now();
+        double secs(double(Duration(begin,end))/TIME_SEC);
+        if (opts.summary) cout << opts.count/secs << endl;
+        else cout << "Time: " << secs << "s Rate: " << opts.count/secs << endl;
     }
 
     ~Client() 
@@ -96,8 +108,8 @@
         try{
             session.close();
             connection.close();
-        } catch(const std::exception& e) {
-            std::cout << e.what() << std::endl;
+        } catch(const exception& e) {
+            cout << e.what() << endl;
         }
     }
 };
@@ -109,8 +121,8 @@
         Client client;
         client.publish();
         return 0;
-    } catch(const std::exception& e) {
-	std::cout << e.what() << std::endl;
+    } catch(const exception& e) {
+	cout << e.what() << endl;
     }
     return 1;
 }

Added: incubator/qpid/trunk/qpid/cpp/src/tests/start_cluster_hosts
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/start_cluster_hosts?rev=689166&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/start_cluster_hosts (added)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/start_cluster_hosts Tue Aug 26 11:35:00 2008
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Start a cluster of brokers on local host, put the list of host port addresses
+# in cluster.ports
+#
+# Arguments: [-k] [-p port] HOST [HOST...]
+#  -p port to start broker on, can be 0. Actual ports recorded in cluster.addr.
+#  -k kill any qpidd processes owned by this user before starting.
+# Start a broker on each named host. Name a host twice to start multiple brokers.
+#
+# You must be able to ssh to each host and have primary group ais.
+# qpidd must exist in the same directory `pwd`/.. as on this host.
+#
+
+ADDR_FILE=cluster.addr
+
+while getopts "kp:" ARG ; do
+    case $ARG in
+	k) KILL=yes ; rm -f $ADDR_FILE ;;
+	p) PORT="$OPTARG" ;;
+	*) echo "Error parsing options: $ARG"; exit 1 ;;
+    esac
+done
+shift `expr $OPTIND - 1`
+test -n "$PORT" && PORTOPT="-p $PORT"
+test -n $KILL && KILL="../qpidd -q $PORTOPT ;"
+
+test -z "$*" && { echo Must specify at least one host; exit 1; }
+test -f $ADDR_FILE && { echo "$ADDR_FILE file already exists" ; exit 1; }
+CLUSTER=$USER			# User name is cluster name.
+OPTS="-d $PORTOPT --load-module ../.libs/libqpidcluster.so  --cluster-name=$CLUSTER --no-data-dir --auth=no --log-output=syslog"
+
+num=0
+for h in $*; do
+    num=`expr $num + 1`	      # Give a unique log prefix to each node.
+    cmd="cd $PWD; $KILL ../qpidd $OPTS --log-prefix $num.$h"
+    out=`ssh $h "$cmd"` || { echo $out ; exit 1; }
+    if [ "$PORT" = 0 ] ; then p=$out; else p=$PORT; fi
+    echo "$h $p" | tee -a $ADDR_FILE
+done
+

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/start_cluster_hosts
------------------------------------------------------------------------------
    svn:executable = *