diff options
author | msoxzw <56633971+msoxzw@users.noreply.github.com> | 2022-04-15 19:59:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-15 12:59:01 -0700 |
commit | 42fabc3ea767f10989363536eaaa9da32616ab57 (patch) | |
tree | 6233bfa04fbe4ad6f367d2f4e05d0acb7553c006 /Lib/asyncio/proactor_events.py | |
parent | c9e231de8551ab6d06c92dfa95033150e52d7f1f (diff) | |
download | cpython-42fabc3ea767f10989363536eaaa9da32616ab57.tar.gz cpython-42fabc3ea767f10989363536eaaa9da32616ab57.zip |
gh-91487: Optimize asyncio UDP speed (GH-91488)
Fix #91487
When transferring a small file, e.g. 256 KiB, the speed of this PR is comparable. However, if a large file, e.g. 65536 KiB, is transferred, asyncio UDP will be over 100 times faster than the original. The speed is presumably significantly faster if a larger file is transferred, e.g. 1048576 KiB.
Automerge-Triggered-By: GH:gpshead
Diffstat (limited to 'Lib/asyncio/proactor_events.py')
-rw-r--r-- | Lib/asyncio/proactor_events.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index ff6d08f78ee..9636c6b4d28 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -459,6 +459,7 @@ class _ProactorDatagramTransport(_ProactorBasePipeTransport, waiter=None, extra=None): self._address = address self._empty_waiter = None + self._buffer_size = 0 # We don't need to call _protocol.connection_made() since our base # constructor does it for us. super().__init__(loop, sock, protocol, waiter=waiter, extra=extra) @@ -471,7 +472,7 @@ class _ProactorDatagramTransport(_ProactorBasePipeTransport, _set_socket_extra(self, sock) def get_write_buffer_size(self): - return sum(len(data) for data, _ in self._buffer) + return self._buffer_size def abort(self): self._force_close(None) @@ -496,6 +497,7 @@ class _ProactorDatagramTransport(_ProactorBasePipeTransport, # Ensure that what we buffer is immutable. self._buffer.append((bytes(data), addr)) + self._buffer_size += len(data) if self._write_fut is None: # No current write operations are active, kick one off @@ -522,6 +524,7 @@ class _ProactorDatagramTransport(_ProactorBasePipeTransport, return data, addr = self._buffer.popleft() + self._buffer_size -= len(data) if self._address is not None: self._write_fut = self._loop._proactor.send(self._sock, data) |