Skip to content

Commit

Permalink
Download timers are now started only after 1st byte gets received fro…
Browse files Browse the repository at this point in the history
…m the server.
  • Loading branch information
Janhouse committed Oct 22, 2012
1 parent 7eef9f2 commit 4e02fec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
5 changes: 4 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -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.)


41 changes: 31 additions & 10 deletions tespeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ]
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4e02fec

Please sign in to comment.