summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--proxy.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/proxy.py b/proxy.py
index 77356f5..d8c8e75 100644
--- a/proxy.py
+++ b/proxy.py
@@ -9,15 +9,16 @@ except ImportError:
ENDPOINTS = [
('10.2.2.11', 8888),
- ('10.3.1.2', 8888),
+ # ('10.3.1.2', 8888),
('10.1.1.156', 8888),
]
#minimum entity size to start a paralel fetch
KB = 1024
-MINIMAL_SIZE = 512 * KB
-BLOCKSIZE_FETCH = 2048 * KB
-BLOCKSIZE_STEP = 512 * KB
+THRESHOLD = 512 * KB
+INIT_BLOCKSIZE = 2048 * KB
+MIN_BLOCKSIZE = 512 * KB
+TIME_SLICE = 5
class Fetcher(asynchat.async_chat):
def __init__(self, reader, endpoint, url, header, range):
@@ -96,11 +97,10 @@ class MultipleProxyReader(object):
self.endpoints_blocksize = []
for i in range(0,len(ENDPOINTS)):
- self.endpoints_time.append(BLOCKSIZE_FETCH/(200*KB))
- self.endpoints_blocksize.append(BLOCKSIZE_FETCH)
+ self.endpoints_blocksize.append(INIT_BLOCKSIZE)
for i in range(0,len(ENDPOINTS)):
- self.start_fetcher(i,1)
+ self.start_fetcher(i,0)
def handle_incoming_data(self, pos, data):
self.blocks[pos] = data
@@ -125,12 +125,10 @@ class MultipleProxyReader(object):
def start_fetcher(self,endpoint,time):
self.find_next_data()
-
- self.endpoints_time[endpoint] = time
- if max(self.endpoints_time) == time:
- self.endpoints_blocksize[endpoint] += BLOCKSIZE_STEP
- elif min(self.endpoints_time) == time:
- self.endpoints_blocksize[endpoint] -= BLOCKSIZE_STEP
+
+ if time == 0:
+ speed = (self.endpoints_blocksize[endpoint] / time)
+ self.endpoints_blocksize[endpoint] = int(speed * TIME_SLICE)
if self.fetch_pos +1 <self.content_length:
print self, "start new fetcher"
@@ -151,7 +149,6 @@ class MultipleProxyReader(object):
#print self, "expect at %s" % self.write_pos, self.blocks.keys()
if self.write_pos in self.blocks.keys():
- r=True
data = self.blocks.pop(self.write_pos)
self.channel.push(data)
self.write_pos += len(data)