summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2009-01-14 17:32:43 +0000
committerAlan Conway <aconway@apache.org>2009-01-14 17:32:43 +0000
commit8610f0e81fffb9045d40365c61cb99b5e023d325 (patch)
treeb3a57344395664d733d1945711a592a0be6232c8 /cpp/src/tests
parent1b94487191070b4a2f64e0c7401a94e0bde1eee0 (diff)
downloadqpid-python-8610f0e81fffb9045d40365c61cb99b5e023d325.tar.gz
Fix logic to generate messages at a specified rate.
Previous logic was sending messages well below the specified rate. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@734452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/latencytest.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/cpp/src/tests/latencytest.cpp b/cpp/src/tests/latencytest.cpp
index 2414944cef..29bafb1a68 100644
--- a/cpp/src/tests/latencytest.cpp
+++ b/cpp/src/tests/latencytest.cpp
@@ -152,6 +152,7 @@ class Sender : public Client
void sendByCount();
Receiver& receiver;
const string data;
+
public:
Sender(const string& queue, Receiver& receiver);
void test();
@@ -340,34 +341,27 @@ void Sender::sendByRate()
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;
- }
}
}