mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-20 17:52:50 +00:00
check_speed.py: run two 1MB uploads and measure the time it takes
This commit is contained in:
parent
f6be35e122
commit
b9d5a4ead4
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user