Performance tuning objects to be downloaded
- rely on dict quasi-random order instead of an additional shuffle - request an object once per minute - stop check after count objects have been found
This commit is contained in:
parent
dbe15d0b99
commit
79893fdc23
|
@ -106,23 +106,15 @@ class Missing(object):
|
||||||
raise ValueError("Must be at least one")
|
raise ValueError("Must be at least one")
|
||||||
with self.lock:
|
with self.lock:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
since = now - 300 # once every 5 minutes
|
since = now - 60 # once every minute
|
||||||
try:
|
objectHashes = []
|
||||||
matchingHashes = {k:v for k, v in self.hashes.iteritems() if current_thread().peer in self.hashes[k]['peers'] and self.hashes[k]['requested'] < since}
|
for objectHash in self.hashes.keys():
|
||||||
if count > len(matchingHashes):
|
if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < since:
|
||||||
count = len(matchingHashes)
|
objectHashes.append(objectHash)
|
||||||
objectHashes = random.sample(matchingHashes, count)
|
|
||||||
except (IndexError, KeyError): # list is empty
|
|
||||||
return None
|
|
||||||
for objectHash in objectHashes:
|
|
||||||
try:
|
|
||||||
self.hashes[objectHash]['peers'].remove(current_thread().peer)
|
self.hashes[objectHash]['peers'].remove(current_thread().peer)
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
if len(self.hashes[objectHash]['peers']) == 0:
|
|
||||||
self.delete(objectHash)
|
|
||||||
else:
|
|
||||||
self.hashes[objectHash]['requested'] = now
|
self.hashes[objectHash]['requested'] = now
|
||||||
|
if len(objectHashes) >= count:
|
||||||
|
break
|
||||||
return objectHashes
|
return objectHashes
|
||||||
|
|
||||||
def delete(self, objectHash):
|
def delete(self, objectHash):
|
||||||
|
|
Reference in New Issue
Block a user