From 9666001e570275fa08a5766639c437d40bbb0545 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 20 Dec 2010 20:18:11 +0100 Subject: improved bucket --- module/network/Bucket.py | 6 ++++-- module/network/HTTPChunk.py | 2 +- module/network/HTTPDownload.py | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'module') diff --git a/module/network/Bucket.py b/module/network/Bucket.py index 04b706ff2..434cbe662 100644 --- a/module/network/Bucket.py +++ b/module/network/Bucket.py @@ -28,14 +28,16 @@ class Bucket: self.lock = Lock() def setRate(self, rate): + self.lock.acquire() self.rate = rate + self.lock.release() def add(self, amount): self.lock.acquire() self.drip() allowable = min(amount, self.rate - self.content) - if allowable < 3072: - allowable = 0 + if allowable > 0: + sleep(0.005) self.content += allowable self.lock.release() diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 0c87283f1..509ff3983 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -53,7 +53,7 @@ class HTTPChunk(HTTPBase): self.speedCalcTime = None self.speedCalcLen = 0 - self.bufferSize = 16*1024 #tune if performance is poor + self.bufferSize = 18*1024 #tune if performance is poor self.resp = None def getSpeed(self): diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index d0e2eeb1f..f17e16492 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -22,6 +22,7 @@ from helper import * from os.path import exists, getsize from os import remove #from shutil import move, copyfileobj +from zlib import decompressobj, MAX_WBITS from cookielib import CookieJar @@ -163,10 +164,10 @@ class HTTPDownload(): decompress = lambda data: data if encoding == "gzip": - gz = zlib.decompressobj(16+zlib.MAX_WBITS) + gz = decompressobj(16+MAX_WBITS) decompress = lambda data: gz.decompress(data) if encoding == "deflate": - df = zlib.decompressobj(-zlib.MAX_WBITS) + df = decompressobj(-MAX_WBITS) decompress = lambda data: df.decompress(data) fname = "%s.chunk%d" % (self.filename, i) @@ -271,7 +272,7 @@ if __name__ == "__main__": import sys from Bucket import Bucket bucket = Bucket() - bucket.setRate(200*1024) + bucket.setRate(3000*1024) bucket = None url = "http://speedtest.netcologne.de/test_100mb.bin" -- cgit v1.2.3