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:
Peter Šurda 2017-10-19 09:02:33 +02:00
parent 7ec3fc7a5a
commit d28a7bfb86
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
1 changed files with 9 additions and 3 deletions

View File

@ -36,12 +36,18 @@ class AdvancedDispatcher(asyncore.dispatcher):
def slice_write_buf(self, length=0):
if length > 0:
with self.writeLock:
del self.write_buf[0:length]
if length >= len(self.write_buf):
del self.write_buf[:]
else:
del self.write_buf[0:length]
def slice_read_buf(self, length=0):
if length > 0:
with self.readLock:
del self.read_buf[0:length]
if length >= len(self.read_buf):
del self.read_buf[:]
else:
del self.read_buf[0:length]
def process(self):
if not self.connected:
@ -77,7 +83,7 @@ class AdvancedDispatcher(asyncore.dispatcher):
if asyncore.maxDownloadRate > 0:
self.downloadChunk = asyncore.downloadBucket
try:
if self.expectBytes > 0 and not self.fullyEstablished:
if self.expectBytes > 0:
self.downloadChunk = min(self.downloadChunk, self.expectBytes - len(self.read_buf))
if self.downloadChunk < 0:
self.downloadChunk = 0