diff options
-rw-r--r-- | module/network/Bucket.py | 5 | ||||
-rw-r--r-- | module/network/HTTPChunk.py | 5 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 8 |
3 files changed, 12 insertions, 6 deletions
diff --git a/module/network/Bucket.py b/module/network/Bucket.py index 1a2d77409..69da277ae 100644 --- a/module/network/Bucket.py +++ b/module/network/Bucket.py @@ -26,7 +26,10 @@ class Bucket: self.tokens = 0 self.timestamp = time() self.lock = Lock() - + + def __nonzero__(self): + return False if self.rate < 10240 else True + def setRate(self, rate): self.lock.acquire() self.rate = int(rate) diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 5cb1d9178..dee185342 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -175,12 +175,17 @@ class HTTPChunk(HTTPRequest): def writeBody(self, buf): size = len(buf) + self.arrived += size self.fp.write(buf) if self.p.bucket: sleep(self.p.bucket.consumed(size)) + else: #@TODO nice to have: traffic sharping algr. which calculates sleep time to reduce cpu load + if size < 5000: + #sleep if chunk size gets low, to avoid many function calls and hope chunksize gets bigger + sleep(0.007) if self.range and self.arrived > (self.range[1]-self.range[0]): return 0 #close if we have enough data diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index 77c5f480f..ecc7f24b8 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -67,7 +67,6 @@ class HTTPDownload(): self.lastArrived = [] self.speeds = [] - @property def speed(self): return sum(self.speeds) @@ -151,7 +150,6 @@ class HTTPDownload(): while 1: ret, num_handles = self.m.perform() - if ret != pycurl.E_CALL_MULTI_PERFORM: break @@ -196,7 +194,7 @@ class HTTPDownload(): if self.abort: raise Abort() - sleep(0.005) #supress busy waiting - limits dl speed to (1 / x) * buffersize + sleep(0.003) #supress busy waiting - limits dl speed to (1 / x) * buffersize self.m.select(1) failed = False @@ -228,7 +226,7 @@ class HTTPDownload(): del self.info if __name__ == "__main__": - url = "http://speedtest.netcologne.de/test_10mb.bin" + url = "http://speedtest.netcologne.de/test_100mb.bin" from Bucket import Bucket @@ -238,5 +236,5 @@ if __name__ == "__main__": print "starting" - dwnld = HTTPDownload(url, "test_10mb.bin", bucket=bucket) + dwnld = HTTPDownload(url, "test_100mb.bin", bucket=bucket) dwnld.download(chunks=3, resume=True)
\ No newline at end of file |