Pending download stats optimisations
- tracks separately a global list for a faster sum. Needs slightly more memory
This commit is contained in:
parent
a746ba9da7
commit
6655e99aa3
|
@ -534,6 +534,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
|||
del connection.objectsNewToThem[hashId]
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
del state.missingObjects[hashId]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def handle_close(self):
|
||||
self.set_state("close")
|
||||
|
|
|
@ -5,6 +5,7 @@ from threading import RLock
|
|||
from debug import logger
|
||||
from inventory import Inventory
|
||||
from network.dandelion import Dandelion
|
||||
from state import missingObjects
|
||||
|
||||
haveBloom = False
|
||||
|
||||
|
@ -82,6 +83,7 @@ class ObjectTracker(object):
|
|||
except KeyError:
|
||||
pass
|
||||
if hashId not in Inventory():
|
||||
missingObjects[hashId] = None
|
||||
with self.objectsNewToMeLock:
|
||||
self.objectsNewToMe[hashId] = True
|
||||
elif hashId in Dandelion().hashMap:
|
||||
|
|
|
@ -2,6 +2,7 @@ import time
|
|||
|
||||
from network.connectionpool import BMConnectionPool
|
||||
import asyncore_pollchoose as asyncore
|
||||
from state import missingObjects
|
||||
|
||||
lastReceivedTimestamp = time.time()
|
||||
lastReceivedBytes = 0
|
||||
|
@ -50,19 +51,20 @@ def downloadSpeed():
|
|||
return currentReceivedSpeed
|
||||
|
||||
def pendingDownload():
|
||||
tmp = {}
|
||||
for connection in BMConnectionPool().inboundConnections.values() + \
|
||||
BMConnectionPool().outboundConnections.values():
|
||||
for k in connection.objectsNewToMe.keys():
|
||||
tmp[k] = True
|
||||
return len(tmp)
|
||||
return len(missingObjects)
|
||||
#tmp = {}
|
||||
#for connection in BMConnectionPool().inboundConnections.values() + \
|
||||
# BMConnectionPool().outboundConnections.values():
|
||||
# for k in connection.objectsNewToMe.keys():
|
||||
# tmp[k] = True
|
||||
#return len(tmp)
|
||||
|
||||
def pendingUpload():
|
||||
tmp = {}
|
||||
for connection in BMConnectionPool().inboundConnections.values() + \
|
||||
BMConnectionPool().outboundConnections.values():
|
||||
for k in connection.objectsNewToThem.keys():
|
||||
tmp[k] = True
|
||||
#tmp = {}
|
||||
#for connection in BMConnectionPool().inboundConnections.values() + \
|
||||
# BMConnectionPool().outboundConnections.values():
|
||||
# for k in connection.objectsNewToThem.keys():
|
||||
# tmp[k] = True
|
||||
#This probably isn't the correct logic so it's disabled
|
||||
#return len(tmp)
|
||||
return 0
|
||||
|
|
|
@ -43,6 +43,9 @@ trustedPeer = None
|
|||
|
||||
discoveredPeers = {}
|
||||
|
||||
# tracking pending downloads globally, for stats
|
||||
missingObjects = {}
|
||||
|
||||
Peer = collections.namedtuple('Peer', ['host', 'port'])
|
||||
|
||||
def resetNetworkProtocolAvailability():
|
||||
|
|
Loading…
Reference in New Issue
Block a user