diff options
author | Alan Conway <aconway@apache.org> | 2008-08-26 18:35:00 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-08-26 18:35:00 +0000 |
commit | 7b71d1fc839fb93d3c3849b9a4ab82597aa423e8 (patch) | |
tree | f72f74630a4db8e1fc86fc6e7c0f22e0fd99672a | |
parent | 5f310c9fb56505765633367334e833192887b70a (diff) | |
download | qpid-python-7b71d1fc839fb93d3c3849b9a4ab82597aa423e8.tar.gz |
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.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@689166 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/tests/consume.cpp | 24 | ||||
-rwxr-xr-x | qpid/cpp/src/tests/perfdist | 14 | ||||
-rw-r--r-- | qpid/cpp/src/tests/publish.cpp | 42 | ||||
-rwxr-xr-x | qpid/cpp/src/tests/start_cluster_hosts | 41 |
4 files changed, 95 insertions, 26 deletions
diff --git a/qpid/cpp/src/tests/consume.cpp b/qpid/cpp/src/tests/consume.cpp index c20a738755..29c61ada1b 100644 --- a/qpid/cpp/src/tests/consume.cpp +++ b/qpid/cpp/src/tests/consume.cpp @@ -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 @@ struct Client 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 @@ struct Client 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 @@ int main(int argc, char** argv) 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; } diff --git a/qpid/cpp/src/tests/perfdist b/qpid/cpp/src/tests/perfdist index 816d2d99f6..b05787f37d 100755 --- a/qpid/cpp/src/tests/perfdist +++ b/qpid/cpp/src/tests/perfdist @@ -33,16 +33,24 @@ while test $# -gt 0; do --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 diff --git a/qpid/cpp/src/tests/publish.cpp b/qpid/cpp/src/tests/publish.cpp index b78f3fdf6d..34c2b8fefc 100644 --- a/qpid/cpp/src/tests/publish.cpp +++ b/qpid/cpp/src/tests/publish.cpp @@ -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 @@ struct Args : public qpid::TestOptions { 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 @@ struct Client 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 @@ struct Client 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 @@ int main(int argc, char** argv) 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; } diff --git a/qpid/cpp/src/tests/start_cluster_hosts b/qpid/cpp/src/tests/start_cluster_hosts new file mode 100755 index 0000000000..1c32247050 --- /dev/null +++ b/qpid/cpp/src/tests/start_cluster_hosts @@ -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 + |