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
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), 25000.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)
+
+ # Sanity check
+ rate = common.compute_rate(10*1000*1000, 1)
+ self.failUnlessReallyEqual(common.abbreviate_rate(rate), "10.00MBps")
+
def test_abbreviate_rate(self):
self.failUnlessReallyEqual(common.abbreviate_rate(None), "")
self.failUnlessReallyEqual(common.abbreviate_rate(1234000), "1.23MBps")
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
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
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
+ else:
+ return compute_rate(file_size, time1+time2)
d.addCallback(_convert)
return d
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
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
(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)
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 = "", ""
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")
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")