Pending download stats optimisations

- tracks separately a global list for a faster sum. Needs slightly
more memory
This commit is contained in:
Peter Šurda 2017-10-20 23:11:33 +02:00
parent a746ba9da7
commit 6655e99aa3
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
4 changed files with 22 additions and 11 deletions

View File

@ -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")

View File

@ -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:

View File

@ -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

View File

@ -43,6 +43,9 @@ trustedPeer = None
discoveredPeers = {}
# tracking pending downloads globally, for stats
missingObjects = {}
Peer = collections.namedtuple('Peer', ['host', 'port'])
def resetNetworkProtocolAvailability():