From 8fa19fa2735e8deac27ed900756a61bfb73fed2e Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 26 Sep 2007 18:16:15 -0700 Subject: [PATCH] check_speed: average multiple pings when measuring RTT --- src/allmydata/control.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/allmydata/control.py b/src/allmydata/control.py index 257da383..31a94359 100644 --- a/src/allmydata/control.py +++ b/src/allmydata/control.py @@ -5,7 +5,7 @@ from twisted.application import service from twisted.internet import defer from foolscap import Referenceable from allmydata.interfaces import RIControlClient -from allmydata.util import testutil, fileutil +from allmydata.util import testutil, fileutil, mathutil from twisted.python import log def get_memory_usage(): @@ -57,8 +57,13 @@ class ControlServer(Referenceable, service.Service, testutil.PollMixin): return get_memory_usage() def remote_measure_peer_response_time(self): + # I'd like to average together several pings, but I don't want this + # phase to take more than 10 seconds. Expect worst-case latency to be + # 300ms. results = {} everyone = list(self.parent.introducer_client.get_all_peers()) + num_pings = int(mathutil.div_ceil(10, (len(everyone) * 0.3))) + everyone = everyone * num_pings d = self._do_one_ping(None, everyone, results) return d def _do_one_ping(self, res, everyone_left, results): @@ -69,9 +74,19 @@ class ControlServer(Referenceable, service.Service, testutil.PollMixin): d = connection.callRemote("get_nodeid") def _done(ignored): stop = time.time() - results[peerid] = stop - start + elapsed = stop - start + if peerid in results: + results[peerid].append(elapsed) + else: + results[peerid] = [elapsed] d.addCallback(_done) d.addCallback(self._do_one_ping, everyone_left, results) + def _average(res): + averaged = {} + for peerid,times in results.iteritems(): + averaged[peerid] = sum(times) / len(times) + return averaged + d.addCallback(_average) return d class SpeedTest: -- 2.45.2