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] del connection.objectsNewToThem[hashId]
except KeyError: except KeyError:
pass pass
try:
del state.missingObjects[hashId]
except KeyError:
pass
def handle_close(self): def handle_close(self):
self.set_state("close") self.set_state("close")

View File

@ -5,6 +5,7 @@ from threading import RLock
from debug import logger from debug import logger
from inventory import Inventory from inventory import Inventory
from network.dandelion import Dandelion from network.dandelion import Dandelion
from state import missingObjects
haveBloom = False haveBloom = False
@ -82,6 +83,7 @@ class ObjectTracker(object):
except KeyError: except KeyError:
pass pass
if hashId not in Inventory(): if hashId not in Inventory():
missingObjects[hashId] = None
with self.objectsNewToMeLock: with self.objectsNewToMeLock:
self.objectsNewToMe[hashId] = True self.objectsNewToMe[hashId] = True
elif hashId in Dandelion().hashMap: elif hashId in Dandelion().hashMap:

View File

@ -2,6 +2,7 @@ import time
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
import asyncore_pollchoose as asyncore import asyncore_pollchoose as asyncore
from state import missingObjects
lastReceivedTimestamp = time.time() lastReceivedTimestamp = time.time()
lastReceivedBytes = 0 lastReceivedBytes = 0
@ -50,19 +51,20 @@ def downloadSpeed():
return currentReceivedSpeed return currentReceivedSpeed
def pendingDownload(): def pendingDownload():
tmp = {} return len(missingObjects)
for connection in BMConnectionPool().inboundConnections.values() + \ #tmp = {}
BMConnectionPool().outboundConnections.values(): #for connection in BMConnectionPool().inboundConnections.values() + \
for k in connection.objectsNewToMe.keys(): # BMConnectionPool().outboundConnections.values():
tmp[k] = True # for k in connection.objectsNewToMe.keys():
return len(tmp) # tmp[k] = True
#return len(tmp)
def pendingUpload(): def pendingUpload():
tmp = {} #tmp = {}
for connection in BMConnectionPool().inboundConnections.values() + \ #for connection in BMConnectionPool().inboundConnections.values() + \
BMConnectionPool().outboundConnections.values(): # BMConnectionPool().outboundConnections.values():
for k in connection.objectsNewToThem.keys(): # for k in connection.objectsNewToThem.keys():
tmp[k] = True # tmp[k] = True
#This probably isn't the correct logic so it's disabled #This probably isn't the correct logic so it's disabled
#return len(tmp) #return len(tmp)
return 0 return 0

View File

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