Asyncore update
- request downloads in bigger chunks - don't put whole objects into the receiveDataQueue
This commit is contained in:
parent
0f3a69adf4
commit
2d7d9c2f92
|
@ -11,8 +11,8 @@ from network.connectionpool import BMConnectionPool
|
|||
import protocol
|
||||
|
||||
class DownloadThread(threading.Thread, StoppableThread):
|
||||
maxPending = 50
|
||||
requestChunk = 100
|
||||
maxPending = 200
|
||||
requestChunk = 1000
|
||||
requestTimeout = 60
|
||||
cleanInterval = 60
|
||||
requestExpires = 600
|
||||
|
|
|
@ -24,17 +24,37 @@ class ReceiveQueueThread(threading.Thread, StoppableThread):
|
|||
def run(self):
|
||||
while not self._stopped and state.shutdown == 0:
|
||||
try:
|
||||
connection = receiveDataQueue.get(block=True, timeout=1)
|
||||
dest = receiveDataQueue.get(block=True, timeout=1)
|
||||
receiveDataQueue.task_done()
|
||||
except Queue.Empty:
|
||||
continue
|
||||
|
||||
if self._stopped:
|
||||
break
|
||||
|
||||
# cycle as long as there is data
|
||||
# methods should return False if there isn't enough data, or the connection is to be aborted
|
||||
|
||||
# state_* methods should return False if there isn't enough data,
|
||||
# or the connection is to be aborted
|
||||
|
||||
try:
|
||||
connection.process()
|
||||
BMConnectionPool().inboundConnections[dest].process()
|
||||
except KeyError:
|
||||
pass
|
||||
except AttributeError:
|
||||
logger.error("Unknown state %s, ignoring", connection.state)
|
||||
|
||||
try:
|
||||
BMConnectionPool().outboundConnections[dest].process()
|
||||
except KeyError:
|
||||
pass
|
||||
except AttributeError:
|
||||
logger.error("Unknown state %s, ignoring", connection.state)
|
||||
|
||||
try:
|
||||
BMConnectionPool().udpSockets[dest].process()
|
||||
except KeyError:
|
||||
pass
|
||||
except AttributeError:
|
||||
# missing command
|
||||
logger.error("Unknown state %s, ignoring", connection.state)
|
||||
|
|
|
@ -190,7 +190,7 @@ class TCPConnection(BMProto, TLSDispatcher):
|
|||
self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, network.connectionpool.BMConnectionPool().streams, False))
|
||||
#print "%s:%i: Sending version" % (self.destination.host, self.destination.port)
|
||||
self.connectedAt = time.time()
|
||||
receiveDataQueue.put(self)
|
||||
receiveDataQueue.put(self.destination)
|
||||
|
||||
def handle_read(self):
|
||||
TLSDispatcher.handle_read(self)
|
||||
|
@ -201,7 +201,7 @@ class TCPConnection(BMProto, TLSDispatcher):
|
|||
knownnodes.knownNodes[s][self.destination]["lastseen"] = time.time()
|
||||
except KeyError:
|
||||
pass
|
||||
receiveDataQueue.put(self)
|
||||
receiveDataQueue.put(self.destination)
|
||||
|
||||
def handle_write(self):
|
||||
TLSDispatcher.handle_write(self)
|
||||
|
|
|
@ -169,5 +169,5 @@ class TLSDispatcher(AdvancedDispatcher):
|
|||
|
||||
self.bm_proto_reset()
|
||||
self.set_state("connection_fully_established")
|
||||
receiveDataQueue.put(self)
|
||||
receiveDataQueue.put(self.destination)
|
||||
return False
|
||||
|
|
|
@ -139,7 +139,7 @@ class UDPSocket(BMProto):
|
|||
# overwrite the old buffer to avoid mixing data and so that self.local works correctly
|
||||
self.read_buf = recdata
|
||||
self.bm_proto_reset()
|
||||
receiveDataQueue.put(self)
|
||||
receiveDataQueue.put(self.destination)
|
||||
|
||||
def handle_write(self):
|
||||
try:
|
||||
|
|
Reference in New Issue
Block a user