From 782ab770cf55d9856a9917ace5924c9d2732af99 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Tue, 22 Mar 2016 11:44:06 +0300 Subject: [PATCH] Simulator: align stats to whole seconds Aligning message sending and stats collection to whole seconds. This allows to merge data from client and server - useful for visualization of message flow. Change-Id: I507c021d851254d4d84e8922de687931f8545864 --- tools/simulator.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/simulator.py b/tools/simulator.py index 962b559b6..3d58a16cf 100755 --- a/tools/simulator.py +++ b/tools/simulator.py @@ -112,7 +112,10 @@ class MessageStatsCollector(object): self.label = label self.buffer = [] # buffer to store messages during report interval self.series = [] # stats for every report interval - threading.Timer(1.0, self.monitor).start() # schedule in a second + + now = time.time() + diff = int(now) - now + 1 # align start to whole seconds + threading.Timer(diff, self.monitor).start() # schedule in a second def monitor(self): threading.Timer(1.0, self.monitor).start() @@ -423,6 +426,11 @@ def send_messages(client_id, client_builder, messages_count, duration): client = client_builder() CLIENTS.append(client) + # align message sending closer to whole seconds + now = time.time() + diff = int(now) - now + 1 + time.sleep(diff) + if duration: with timeutils.StopWatch(duration) as stop_watch: while not stop_watch.expired():