Asyncore performance optimisation
- don't transfer unnecessary amount of bytes from network buffers - slice buffer more efficiently if it results in an empty buffer
This commit is contained in:
parent
7ec3fc7a5a
commit
d28a7bfb86
|
@ -36,11 +36,17 @@ class AdvancedDispatcher(asyncore.dispatcher):
|
||||||
def slice_write_buf(self, length=0):
|
def slice_write_buf(self, length=0):
|
||||||
if length > 0:
|
if length > 0:
|
||||||
with self.writeLock:
|
with self.writeLock:
|
||||||
|
if length >= len(self.write_buf):
|
||||||
|
del self.write_buf[:]
|
||||||
|
else:
|
||||||
del self.write_buf[0:length]
|
del self.write_buf[0:length]
|
||||||
|
|
||||||
def slice_read_buf(self, length=0):
|
def slice_read_buf(self, length=0):
|
||||||
if length > 0:
|
if length > 0:
|
||||||
with self.readLock:
|
with self.readLock:
|
||||||
|
if length >= len(self.read_buf):
|
||||||
|
del self.read_buf[:]
|
||||||
|
else:
|
||||||
del self.read_buf[0:length]
|
del self.read_buf[0:length]
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
@ -77,7 +83,7 @@ class AdvancedDispatcher(asyncore.dispatcher):
|
||||||
if asyncore.maxDownloadRate > 0:
|
if asyncore.maxDownloadRate > 0:
|
||||||
self.downloadChunk = asyncore.downloadBucket
|
self.downloadChunk = asyncore.downloadBucket
|
||||||
try:
|
try:
|
||||||
if self.expectBytes > 0 and not self.fullyEstablished:
|
if self.expectBytes > 0:
|
||||||
self.downloadChunk = min(self.downloadChunk, self.expectBytes - len(self.read_buf))
|
self.downloadChunk = min(self.downloadChunk, self.expectBytes - len(self.read_buf))
|
||||||
if self.downloadChunk < 0:
|
if self.downloadChunk < 0:
|
||||||
self.downloadChunk = 0
|
self.downloadChunk = 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user