Commit 0e4d500588f16260d92002d4242aedaad24699a5

Authored by Patric Stout
1 parent 2eed0cfe

fix(example-stress): distribute over 10 topcs to get more out of some brokers

Some brokers work a lot better if you don't hammer everything on
a single topic. Others are less fuzzed about it.
Showing 1 changed file with 11 additions and 3 deletions
example/stress/main.cpp
... ... @@ -30,7 +30,7 @@ int main()
30 30 int64_t totalLatency = 0;
31 31  
32 32 // Subscribe to the topic we are going to stress test.
33   - client.subscribe("test/test/test", [&received, &totalLatency](const std::string topic, const std::string payload)
  33 + client.subscribe("example/stress/+", [&received, &totalLatency](const std::string topic, const std::string payload)
34 34 {
35 35 // Calculate the latency.
36 36 auto now = std::chrono::steady_clock::now();
... ... @@ -47,13 +47,17 @@ int main()
47 47 // means.
48 48 bool is_failing = true;
49 49 auto start = std::chrono::steady_clock::now();
  50 + int channel = 0;
50 51 while (true)
51 52 {
52 53 auto now = std::chrono::steady_clock::now();
53 54 auto now_ms = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
54 55  
55   - // Publish the current time, so we can check the latency.
56   - if (!client.publish("test/test/test", std::to_string(now_ms), false))
  56 + // Publish the current time, so we can check the latency. We distribute
  57 + // it over multiple topics, to give brokers a chance to distrubte the
  58 + // load on their side.
  59 + channel = (channel + 1) % 10;
  60 + if (!client.publish("example/stress/" + std::to_string(channel), std::to_string(now_ms), false))
57 61 {
58 62 failed++;
59 63 }
... ... @@ -69,6 +73,10 @@ int main()
69 73 {
70 74 std::cout << "Sent: " << sent << "/s - Received: " << received << "/s - Failed: " << failed << "/s - Avg Latency: " << (totalLatency / received) << "us" << std::endl;
71 75 }
  76 + else
  77 + {
  78 + std::cout << "Sent: " << sent << "/s - Received: " << received << "/s - Failed: " << failed << "/s " << std::endl;
  79 + }
72 80 sent = 0;
73 81 received = 0;
74 82 failed = 0;
... ...