Sat Aug 14 12:04:25 CEST 2010 francois@ctrlaltdel.ch * web: refactor rate computation, fixes #1166 New patches: [web: refactor rate computation, fixes #1166 francois@ctrlaltdel.ch**20100814100425 Ignore-this: d9a47e9b81b79c70ee8dca273627d10a ] { hunk ./src/allmydata/test/test_web.py 90 ds.add_segment_request(2, now+4) ds.add_segment_request(3, now+5) + # simulate a segment which gets delivered faster than a system clock tick (ticket #1166) + ds.add_segment_request(4, now) + ds.add_segment_delivery(4, now, 0, 140, 0.5) + e = ds.add_dyhb_sent("serverid_a", now) e.finished([1,2], now+1) e = ds.add_dyhb_sent("serverid_b", now+2) # left unfinished hunk ./src/allmydata/test/test_web.py 3176 self.failUnlessReallyEqual(common.abbreviate_time(0.000123), "123us") self.failUnlessReallyEqual(common.abbreviate_time(-123000), "-123000000000us") + def test_compute_rate(self): + self.failUnlessReallyEqual(common.compute_rate(None, None), None) + self.failUnlessReallyEqual(common.compute_rate(None, 1), None) + self.failUnlessReallyEqual(common.compute_rate(250000, None), None) + self.failUnlessReallyEqual(common.compute_rate(250000, 0), None) + self.failUnlessReallyEqual(common.compute_rate(250000, 10), 2500.0) + self.failUnlessReallyEqual(common.compute_rate(0, 10), 0.0) + self.shouldFail(AssertionError, "test_compute_rate", "", + common.compute_rate, -100, 10) + self.shouldFail(AssertionError, "test_compute_rate", "", + common.compute_rate, 100, -10) + + def test_abbreviate_rate(self): self.failUnlessReallyEqual(common.abbreviate_rate(None), "") self.failUnlessReallyEqual(common.abbreviate_rate(1234000), "1.23MBps") hunk ./src/allmydata/web/common.py 93 return "%.1fms" % (1000*s) return "%.0fus" % (1000000*s) +def compute_rate(bytes, seconds): + if bytes is None: + return None + + if seconds is None or seconds == 0: + return None + + # negative values don't make sense here + assert bytes > -1 + assert seconds > 0 + + return 0.1 * bytes / seconds + def abbreviate_rate(data): # 21.8kBps, 554.4kBps 4.37MBps if data is None: hunk ./src/allmydata/web/status.py 8 from nevow import rend, inevow, tags as T from allmydata.util import base32, idlib from allmydata.web.common import getxmlfile, get_arg, \ - abbreviate_time, abbreviate_rate, abbreviate_size, plural + abbreviate_time, abbreviate_rate, abbreviate_size, plural, compute_rate from allmydata.interfaces import IUploadStatus, IDownloadStatus, \ IPublishStatus, IRetrieveStatus, IServermapUpdaterStatus hunk ./src/allmydata/web/status.py 113 def _convert(r): file_size = r.file_size time = r.timings.get(name) - if time is None: - return None - try: - return 1.0 * file_size / time - except ZeroDivisionError: - return None + return compute_rate(file_size, time) d.addCallback(_convert) return d hunk ./src/allmydata/web/status.py 135 file_size = r.file_size time1 = r.timings.get("cumulative_encoding") time2 = r.timings.get("cumulative_sending") - if (file_size is None or time1 is None or time2 is None): - return None - try: - return 1.0 * file_size / (time1+time2) - except ZeroDivisionError: + if (time1 is None or time2 is None): return None hunk ./src/allmydata/web/status.py 137 + else: + return compute_rate(file_size, time1+time2) d.addCallback(_convert) return d hunk ./src/allmydata/web/status.py 147 def _convert(r): fetch_size = r.ciphertext_fetched time = r.timings.get("cumulative_fetch") - if (fetch_size is None or time is None): - return None - try: - return 1.0 * fetch_size / time - except ZeroDivisionError: - return None + return compute_rate(fetch_size, time) d.addCallback(_convert) return d hunk ./src/allmydata/web/status.py 299 def _convert(r): file_size = r.file_size time = r.timings.get(name) - if time is None: - return None - try: - return 1.0 * file_size / time - except ZeroDivisionError: - return None + return compute_rate(file_size, time) d.addCallback(_convert) return d hunk ./src/allmydata/web/status.py 419 (start, length, requesttime, finishtime, bytes, decrypt, paused) = r_ev if finishtime is not None: rtt = finishtime - requesttime - paused - speed = self.render_rate(None, 1.0 * bytes / rtt) + speed = self.render_rate(None, compute_rate(bytes, rtt)) rtt = self.render_time(None, rtt) decrypt = self.render_time(None, decrypt) paused = self.render_time(None, paused) hunk ./src/allmydata/web/status.py 445 elif etype == "delivery": if reqtime[0] == segnum: segtime = when - reqtime[1] - speed = self.render_rate(None, 1.0 * seglen / segtime) + speed = self.render_rate(None, compute_rate(seglen, segtime)) segtime = self.render_time(None, segtime) else: segtime, speed = "", "" hunk ./src/allmydata/web/status.py 581 def _get_rate(self, data, name): file_size = self.retrieve_status.get_size() time = self.retrieve_status.timings.get(name) - if time is None or file_size is None: - return None - try: - return 1.0 * file_size / time - except ZeroDivisionError: - return None + return compute_rate(file_size, time) def data_time_total(self, ctx, data): return self.retrieve_status.timings.get("total") hunk ./src/allmydata/web/status.py 682 def _get_rate(self, data, name): file_size = self.publish_status.get_size() time = self.publish_status.timings.get(name) - if time is None: - return None - try: - return 1.0 * file_size / time - except ZeroDivisionError: - return None + return compute_rate(file_size, time) def data_time_total(self, ctx, data): return self.publish_status.timings.get("total") } Context: [docs: doc of the download status page zooko@zooko.com**20100814054117 Ignore-this: a82ec33da3c39a7c0d47a7a6b5f81bbb ref: http://tahoe-lafs.org/trac/tahoe-lafs/ticket/1169#comment:1 ] [docs: NEWS: edit English usage, remove ticket numbers for regressions vs. 1.7.1 that were fixed again before 1.8.0c2 zooko@zooko.com**20100811071758 Ignore-this: 993f5a1e6a9535f5b7a0bd77b93b66d0 ] [docs: NEWS: more detail about new-downloader zooko@zooko.com**20100811071303 Ignore-this: 9f07da4dce9d794ce165aae287f29a1e ] [TAG allmydata-tahoe-1.8.0c2 david-sarah@jacaranda.org**20100810073847 Ignore-this: c37f732b0e45f9ebfdc2f29c0899aeec ] Patch bundle hash: 007b9adc44128641507932e636472f80850916d6