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 2009/01/14 18:32:44 UTC
svn commit: r734452 - /qpid/trunk/qpid/cpp/src/tests/latencytest.cpp
Author: aconway
Date: Wed Jan 14 09:32:43 2009
New Revision: 734452
URL: http://svn.apache.org/viewvc?rev=734452&view=rev
Log:
Fix logic to generate messages at a specified rate.
Previous logic was sending messages well below the specified rate.
Modified:
qpid/trunk/qpid/cpp/src/tests/latencytest.cpp
Modified: qpid/trunk/qpid/cpp/src/tests/latencytest.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/latencytest.cpp?rev=734452&r1=734451&r2=734452&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/latencytest.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/latencytest.cpp Wed Jan 14 09:32:43 2009
@@ -152,6 +152,7 @@
void sendByCount();
Receiver& receiver;
const string data;
+
public:
Sender(const string& queue, Receiver& receiver);
void test();
@@ -340,34 +341,27 @@
if (opts.durable) {
msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT);
}
-
- //calculate interval (in micro secs) between messages to achieve desired rate
- uint64_t interval = (1000*1000)/opts.rate;
- uint64_t timeLimit(opts.timeLimit * TIME_SEC);
- uint64_t start(current_time());
-
+ uint64_t interval = TIME_SEC/opts.rate;
+ int64_t timeLimit = opts.timeLimit * TIME_SEC;
+ uint64_t sent = 0, missedRate = 0;
+ AbsTime start = now();
while (true) {
- uint64_t start_msg(current_time());
- msg.getDeliveryProperties().setTimestamp(start_msg);
+ AbsTime sentAt=now();
+ msg.getDeliveryProperties().setTimestamp(Duration(sentAt));
async(session).messageTransfer(arg::content=msg, arg::acceptMode=1);
if (opts.sync) session.sync();
-
- uint64_t now = current_time();
-
- if (timeLimit != 0 && (now - start) > timeLimit) {
+ ++sent;
+ AbsTime waitTill(start, sent*interval);
+ Duration delay(sentAt, waitTill);
+ if (delay < 0)
+ ++missedRate;
+ else
+ sys::usleep(delay / TIME_USEC);
+ if (timeLimit != 0 && Duration(start, now()) > timeLimit) {
session.sync();
receiver.stop();
break;
}
-
- uint64_t timeTaken = (now - start_msg) / TIME_USEC;
- if (timeTaken < interval) {
- qpid::sys::usleep(interval - timeTaken);
- } else if (timeTaken > interval &&
- !opts.csv && !opts.cumulative) { // Don't be so verbose in this case, we're piping the results to another program
- std::cout << "Could not achieve desired rate! (Took " << timeTaken
- << " microsecs to send message, aiming for " << interval << " microsecs)" << std::endl;
- }
}
}