From: Brian Warner Date: Thu, 20 Sep 2007 01:40:18 +0000 (-0700) Subject: check_speed.py: run two 1MB uploads and measure the time it takes X-Git-Tag: allmydata-tahoe-0.6.0~51 X-Git-Url: https://git.rkrishnan.org/provisioning?a=commitdiff_plain;h=b9d5a4ead4b3ddd47a503980096c8e01635a0f87;p=tahoe-lafs%2Ftahoe-lafs.git check_speed.py: run two 1MB uploads and measure the time it takes --- 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):