]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
check_speed.py: run two 1MB uploads and measure the time it takes
authorBrian Warner <warner@allmydata.com>
Thu, 20 Sep 2007 01:40:18 +0000 (18:40 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 20 Sep 2007 01:40:18 +0000 (18:40 -0700)
src/allmydata/control.py
src/allmydata/interfaces.py
src/allmydata/test/check_speed.py

index 4158ae66cbed50b31a5d966961b1d33fa3d77bfa..69f4410e7c2f779f4819ec5e1092f7c32d3a3b45 100644 (file)
@@ -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()
index 993cbd129e7ba24ab55ad4fc7c061c4e481d64ac..2e03580872b66071d8c49d2162874257a47367c8 100644 (file)
@@ -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
index c3e0d90506906f149b7b603eafecb70e8b073100..4002237e7cab971297254bf3784bfc980d471a07 100644 (file)
@@ -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):