From 4e02fece1f542cc6cee91a30de91ffc27317e8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Jansons?= Date: Mon, 22 Oct 2012 20:06:59 +0300 Subject: [PATCH] Download timers are now started only after 1st byte gets received from the server. --- README | 5 ++++- tespeed.py | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README b/README index 621171a..6f5d5b7 100644 --- a/README +++ b/README @@ -52,6 +52,9 @@ TODO: * Store the measurement data and draw graphs. * Measure the speed for the whole network interface (similar like it was in the old version of Tespeed). - + * Start upload timer only after 1st byte is read. + * Figure out the ammount of data that was transfered only when all threads were + actively sendong/receiving data at the same time. (Should provide more precise + test results.) diff --git a/tespeed.py b/tespeed.py index be9f7ba..448c84c 100755 --- a/tespeed.py +++ b/tespeed.py @@ -187,7 +187,8 @@ def PostRequest(self, uri, stream): def ChunkReport(self, bytes_so_far, chunk_size, total_size, num, th, d, w): - # Receiving status update from download/upload thread + # Receiving status update from download thread + if w==1: return d[num]=bytes_so_far @@ -208,21 +209,29 @@ def ChunkReport(self, bytes_so_far, chunk_size, total_size, num, th, d, w): def ChunkRead(self, response, num, th, d, w=0, chunk_size=10240, report_hook=None): - + #print "Thread num ", th, num, d, " starting to report\n" if(w==1): return [0,0,0] + total_size = response.info().getheader('Content-Length').strip() total_size = int(total_size) bytes_so_far = 0 - start = time.time() + start=0 while 1: - chunk = response.read(chunk_size) - bytes_so_far += len(chunk) - if not chunk: - break - if report_hook: - report_hook(bytes_so_far, chunk_size, total_size, num, th, d, w) + chunk=0 + if start == 0: + #print "Started receiving data" + chunk = response.read(1) + start = time.time() + + else: + chunk = response.read(chunk_size) + if not chunk: + break + bytes_so_far += len(chunk) + if report_hook: + report_hook(bytes_so_far, chunk_size, total_size, num, th, d, w) end = time.time() return [ bytes_so_far, start, end ] @@ -346,8 +355,20 @@ def AsyncRequest(self, url, num, upload=0): if connections[c]['end'] is not False: #tspeed=tspeed+(connections[c]['size']/(connections[c]['end']-connections[c]['start'])) sizes=sizes+connections[c]['size'] + + # Using more precise times for downloads + if upload==0: + if c==0: + start=connections[c]['start'] + end=connections[c]['end'] + else: + if connections[c]['start'] < start: + start=connections[c]['start'] + if connections[c]['end'] > end: + end=connections[c]['end'] + took=end-start - + return [sizes, took] def TestUpload(self):