I did this for a customer but since it is so funny I'll share it with you as well.
The task is to monitor the latency of MQTT to see how high load impacts latency to connected devices.
I have one script that simply every 20 seconds
- Generate a timestamp with nanoseconds precision.
- Publish it using mosquitto_pub to a topic
Then another script subscribes to the same topic and when a timestamp is received it calculates the time difference between now and the timestamp in the message. The script are run on the same machine to be using the same time-source.
The scripts are available here.
The scripts are not executed in the same place as the broker being tested but rather in my home about 100 km from the server vault.
The output from the listener looks like:
1676799030765952899:.0318
1676799050799585763:.0342
1676799070832329096:.0342
1676799090864327653:.0339
1676799110896101004:.0329
1676799130931456678:.0366
1676799150962834780:.0330
1676799170994089948:.0327
1676799191027117633:.0351
1676799211059608180:.0343
1676799231091031539:.0333
1676799251120667014:.0317
1676799271147925654:.0290
1676799291181852002:.0349
1676799311211758820:.0318
1676799331245124725:.0338
1676799351276887370:.0335
1676799371309271405:.0338
It seems to settle at 0.02 - 0.04 seconds.
Then i started a spammer that we have that through 400 workers pushes 4 millions messages as fast as it can. That is about 1 million messages per minute. During that session the output was llike:
1676799771927281815:.0294
1676799791957378783:.0306
1676799811984715868:.0299
1676799832629805693:.6470
1676799852725571137:.2164
1676799872875600869:.2308
1676799892989083646:.1960
1676799913135008866:.2180
1676799933253496172:.2119
1676799953395697642:.2220
1676799973548164156:.2332
1676799993667128208:.2103
1676800013833744282:.2490
1676800033961443157:.2132
1676800054099452763:.2215
1676800074241286677:.2339
1676800094343959992:.1937
1676800114501210886:.2380
1676800134647904664:.2365
1676800154752448790:.1958
1676800174879842215:.2073
1676800195003074154:.2028
1676800215164057243:.2518
1676800235302944820:.2253
1676800255397627204:.1793
1676800275364334463:.0341
1676800295396530550:.0324
1676800315427032602:.0316
So we can the the latency is rising to about 0,2 secunds during very light load. That is acceptable to me 😃