From: Brian Warner Date: Mon, 1 Aug 2011 04:39:32 +0000 (-0700) Subject: Coalesce multiple Share.loop() calls, make downloads faster. Closes #1268. X-Git-Url: https://git.rkrishnan.org/Site/Content/Exhibitors/simplejson/?a=commitdiff_plain;h=c9def7697757bdae20804a058493710fcff0cab3;p=tahoe-lafs%2Ftahoe-lafs.git Coalesce multiple Share.loop() calls, make downloads faster. Closes #1268. --- diff --git a/src/allmydata/immutable/downloader/share.py b/src/allmydata/immutable/downloader/share.py index 95173ae6..1918d902 100644 --- a/src/allmydata/immutable/downloader/share.py +++ b/src/allmydata/immutable/downloader/share.py @@ -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):