]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Coalesce multiple Share.loop() calls, make downloads faster. Closes #1268.
authorBrian Warner <warner@lothar.com>
Mon, 1 Aug 2011 04:39:32 +0000 (21:39 -0700)
committerBrian Warner <warner@lothar.com>
Mon, 1 Aug 2011 15:18:34 +0000 (08:18 -0700)
src/allmydata/immutable/downloader/share.py

index 95173ae6d3fee501dfec66a21bb2c286bbc78630..1918d902538f33273b4a5c3e8141ec3ee37da013 100644 (file)
@@ -52,6 +52,7 @@ class Share:
         self._dyhb_rtt = dyhb_rtt
         # self._alive becomes False upon fatal corruption or server error
         self._alive = True
+        self._loop_scheduled = False
         self._lp = log.msg(format="%(share)s created", share=repr(self),
                            level=log.NOISY, parent=logparent, umid="P7hv2w")
 
@@ -164,7 +165,7 @@ class Share:
                 break
         else:
             self._requested_blocks.append( (segnum, set([o])) )
-        eventually(self.loop)
+        self.schedule_loop()
         return o
 
     def _cancel_block_request(self, o):
@@ -184,7 +185,14 @@ class Share:
             return self._requested_blocks[0]
         return None, []
 
+    def schedule_loop(self):
+        if self._loop_scheduled:
+            return
+        self._loop_scheduled = True
+        eventually(self.loop)
+
     def loop(self):
+        self._loop_scheduled = False
         if not self._alive:
             return
         try:
@@ -797,7 +805,7 @@ class Share:
 
     def _trigger_loop(self, res):
         if self._alive:
-            eventually(self.loop)
+            self.schedule_loop()
         return res
 
     def _fail(self, f, level=log.WEIRD):