From b9d5a4ead4b3ddd47a503980096c8e01635a0f87 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 19 Sep 2007 18:40:18 -0700 Subject: [PATCH] check_speed.py: run two 1MB uploads and measure the time it takes --- src/allmydata/control.py | 30 +++++++++++++++++++++++++++++- src/allmydata/interfaces.py | 6 ++++++ src/allmydata/test/check_speed.py | 14 +++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/allmydata/control.py b/src/allmydata/control.py index 4158ae66..69f4410e 100644 --- a/src/allmydata/control.py +++ b/src/allmydata/control.py @@ -1,9 +1,10 @@ +import os, time from zope.interface import implements from twisted.application import service from foolscap import Referenceable from allmydata.interfaces import RIControlClient -from allmydata.util import testutil +from allmydata.util import testutil, idlib from twisted.python import log def get_memory_usage(): @@ -50,5 +51,32 @@ class ControlServer(Referenceable, service.Service, testutil.PollMixin): d.addCallback(lambda res: filename) return d + def remote_upload_speed_test(self, size): + """Write a tempfile to disk of the given size. Measure how long + it takes to upload it to the servers. + """ + assert size > 8 + fn = os.path.join(self.parent.basedir, idlib.b2a(os.urandom(8))) + f = open(fn, "w") + f.write(os.urandom(8)) + size -= 8 + while size > 0: + chunk = min(size, 4096) + f.write("\x00" * chunk) + size -= chunk + f.close() + uploader = self.parent.getServiceNamed("uploader") + start = time.time() + d = uploader.upload_filename(fn) + def _done(uri): + stop = time.time() + return stop - start + d.addCallback(_done) + def _cleanup(res): + os.unlink(fn) + return res + d.addBoth(_cleanup) + return d + def remote_get_memory_usage(self): return get_memory_usage() diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index 993cbd12..2e035808 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -1053,3 +1053,9 @@ class RIControlClient(RemoteInterface): keys are 'VmPeak', 'VmSize', and 'VmData'. The values are integers, measuring memory consupmtion in bytes.""" return DictOf(str, int) + + def upload_speed_test(size=int): + """Write a tempfile to disk of the given size. Measure how long + it takes to upload it to the servers. + """ + return float diff --git a/src/allmydata/test/check_speed.py b/src/allmydata/test/check_speed.py index c3e0d905..4002237e 100644 --- a/src/allmydata/test/check_speed.py +++ b/src/allmydata/test/check_speed.py @@ -15,6 +15,7 @@ class SpeedTest: f.close() self.base_service = service.MultiService() self.failed = None + self.times = {} def run(self): print "STARTING" @@ -54,12 +55,23 @@ class SpeedTest: reactor.callLater(delay, d.callback, result) return d + def record_time(self, time, key): + print "TIME (%s): %s" % (key, time) + self.times[key] = time + def do_test(self): print "doing test" - d = self.client_rref.callRemote("get_memory_usage") + rr = self.client_rref + d = rr.callRemote("get_memory_usage") def _got(res): print "MEMORY USAGE:", res d.addCallback(_got) + d.addCallback(lambda res: rr.callRemote("upload_speed_test", 1000)) + d.addCallback(self.record_time, "startup") + d.addCallback(lambda res: rr.callRemote("upload_speed_test", int(1e6))) + d.addCallback(self.record_time, "1MB.1") + d.addCallback(lambda res: rr.callRemote("upload_speed_test", int(1e6))) + d.addCallback(self.record_time, "1MB.2") return d def tearDown(self, res): -- 2.45.2