From: Brian Warner Date: Thu, 27 Sep 2007 01:16:15 +0000 (-0700) Subject: check_speed: average multiple pings when measuring RTT X-Git-Tag: allmydata-tahoe-0.6.1~67 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/...?a=commitdiff_plain;h=8fa19fa2735e8deac27ed900756a61bfb73fed2e;p=tahoe-lafs%2Ftahoe-lafs.git check_speed: average multiple pings when measuring RTT --- 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: