From 41ead2bfb5d0d2e61c9559042814b45b246d4c91 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 2 Dec 2017 00:48:08 +0100 Subject: [PATCH] Distribute downloads more evenly - also increases expireation of missing objects from 10 minutes to an hour --- src/network/downloadthread.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/network/downloadthread.py b/src/network/downloadthread.py index 8c384edc..0cbdac16 100644 --- a/src/network/downloadthread.py +++ b/src/network/downloadthread.py @@ -13,10 +13,10 @@ from state import missingObjects class DownloadThread(threading.Thread, StoppableThread): minPending = 200 - requestChunk = 1000 + maxRequestChunk = 1000 requestTimeout = 60 cleanInterval = 60 - requestExpires = 600 + requestExpires = 3600 def __init__(self): threading.Thread.__init__(self, name="Downloader") @@ -42,6 +42,7 @@ class DownloadThread(threading.Thread, StoppableThread): # Choose downloading peers randomly connections = BMConnectionPool().inboundConnections.values() + BMConnectionPool().outboundConnections.values() random.shuffle(connections) + requestChunk = max(int(DownloadThread.maxRequestChunk / len(connections)), 1) for i in connections: now = time.time() timedOut = now - DownloadThread.requestTimeout @@ -61,8 +62,8 @@ class DownloadThread(threading.Thread, StoppableThread): random.shuffle(request) if not request: continue - if len(request) > DownloadThread.requestChunk - downloadPending: - request = request[:DownloadThread.requestChunk - downloadPending] + if len(request) > requestChunk - downloadPending: + request = request[:requestChunk - downloadPending] # mark them as pending for k in request: i.objectsNewToMe[k] = False