You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2008/01/15 12:34:37 UTC

svn commit: r612086 - /incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp

Author: gsim
Date: Tue Jan 15 03:34:18 2008
New Revision: 612086

URL: http://svn.apache.org/viewvc?rev=612086&view=rev
Log:
Added option for making each published message have unique data (that can be tracked e.g. for latency measurement)


Modified:
    incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp?rev=612086&r1=612085&r2=612086&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp Tue Jan 15 03:34:18 2008
@@ -79,6 +79,7 @@
     size_t size;
     bool confirm;
     bool durable;
+    bool uniqueData;
 
     // Subscriber
     size_t subs;
@@ -94,7 +95,7 @@
     Opts() :
         TestOptions(helpText),
         setup(false), control(false), publish(false), subscribe(false),
-        pubs(1), count(500000), size(1024), confirm(true), durable(false),
+        pubs(1), count(500000), size(1024), confirm(true), durable(false), uniqueData(false),
         subs(1), ack(0),
         qt(1), mode(SHARED), summary(false)
     {
@@ -114,6 +115,7 @@
             ("size", optValue(size, "BYTES"), "Size of messages in bytes.")
             ("pub-confirm", optValue(confirm, "yes|no"), "Publisher use confirm-mode.")
             ("durable", optValue(durable, "yes|no"), "Publish messages as durable.")
+            ("unique-data", optValue(uniqueData, "yes|no"), "Make data for each message unique.")
 
             ("nsubs", optValue(subs, "N"), "Create N subscribers.")
             ("sub-ack", optValue(ack, "N"), "N>0: Subscriber acks batches of N.\n"
@@ -368,11 +370,29 @@
     void run() {                // Publisher
         Completion completion;
         try {
-            size_t msgSize=max(opts.size, sizeof(size_t));
-            Message msg(string(msgSize, 'X'), routingKey);
+            string data;
+            size_t offset(0);
+            if (opts.uniqueData) {
+                offset = 5;
+                data += "data:";//marker (requested for latency testing tool scripts)
+                data += string(sizeof(size_t), 'X');//space for seq no
+                data += string(reinterpret_cast<const char*>(session.getId().data()), session.getId().size());
+                if (opts.size > data.size()) {
+                    data += string(opts.size - data.size(), 'X');
+                } else if(opts.size < data.size()) {
+                    cout << "WARNING: Increased --size to " << data.size()
+                         << " to honour --unique-data" << endl;
+                }
+            } else {
+                size_t msgSize=max(opts.size, sizeof(size_t));
+                data = string(msgSize, 'X');                
+            }
+
+            Message msg(data, routingKey);
             if (opts.durable)
                 msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT);
 
+
             SubscriptionManager subs(session);
             LocalQueue lq(AckPolicy(opts.ack));
             subs.setFlowControl(1, SubscriptionManager::UNLIMITED, false); 
@@ -383,7 +403,7 @@
             for (size_t i=0; i<opts.count; i++) {
                 // Stamp the iteration into the message data, avoid
                 // any heap allocation.
-                const_cast<std::string&>(msg.getData()).replace(0, sizeof(uint32_t), reinterpret_cast<const char*>(&i), sizeof(uint32_t));
+                const_cast<std::string&>(msg.getData()).replace(offset, sizeof(uint32_t), reinterpret_cast<const char*>(&i), sizeof(uint32_t));
                 completion = session.messageTransfer(
                     arg::destination=destination,
                     arg::content=msg,
@@ -458,7 +478,8 @@
                 // here, e.g. no std::map, std::string etc.
                 //
                 // For now verify order only for a single publisher.
-                size_t n = *reinterpret_cast<const uint32_t*>(msg.getData().data());
+                size_t offset = opts.uniqueData ? 5 /*marker is 'data:'*/ : 0;
+                size_t n = *reinterpret_cast<const uint32_t*>(msg.getData().data() + offset);
                 if (opts.pubs == 1) {
                     if (opts.subs == 1 || opts.mode == FANOUT) verify(n==expect, "==", expect, n);
                     else verify(n>=expect, ">=", expect, n);