mirror of
https://github.com/python/cpython.git
synced 2024-12-04 07:15:09 +08:00
Issue #20540: Fix a performance regression (vs. Python 3.2) when layering a multiprocessing Connection over a TCP socket.
For small payloads, Nagle's algorithm would introduce idle delays before the entire transmission of a message.
This commit is contained in:
parent
b4062e8f8a
commit
b7d6d2ac6e
@ -395,13 +395,23 @@ class Connection(_ConnectionBase):
|
|||||||
return buf
|
return buf
|
||||||
|
|
||||||
def _send_bytes(self, buf):
|
def _send_bytes(self, buf):
|
||||||
# For wire compatibility with 3.2 and lower
|
|
||||||
n = len(buf)
|
n = len(buf)
|
||||||
self._send(struct.pack("!i", n))
|
# For wire compatibility with 3.2 and lower
|
||||||
# The condition is necessary to avoid "broken pipe" errors
|
header = struct.pack("!i", n)
|
||||||
# when sending a 0-length buffer if the other end closed the pipe.
|
if n > 16384:
|
||||||
if n > 0:
|
# The payload is large so Nagle's algorithm won't be triggered
|
||||||
self._send(buf)
|
# and we'd better avoid the cost of concatenation.
|
||||||
|
chunks = [header, buf]
|
||||||
|
elif n > 0:
|
||||||
|
# Issue # 20540: concatenate before sending, to avoid delays due
|
||||||
|
# to Nagle's algorithm on a TCP socket.
|
||||||
|
chunks = [header + buf]
|
||||||
|
else:
|
||||||
|
# This code path is necessary to avoid "broken pipe" errors
|
||||||
|
# when sending a 0-length buffer if the other end closed the pipe.
|
||||||
|
chunks = [header]
|
||||||
|
for chunk in chunks:
|
||||||
|
self._send(chunk)
|
||||||
|
|
||||||
def _recv_bytes(self, maxsize=None):
|
def _recv_bytes(self, maxsize=None):
|
||||||
buf = self._recv(4)
|
buf = self._recv(4)
|
||||||
|
@ -48,6 +48,11 @@ Core and Builtins
|
|||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #20540: Fix a performance regression (vs. Python 3.2) when layering
|
||||||
|
a multiprocessing Connection over a TCP socket. For small payloads, Nagle's
|
||||||
|
algorithm would introduce idle delays before the entire transmission of a
|
||||||
|
message.
|
||||||
|
|
||||||
- Issue #16983: the new email header parsing code will now decode encoded words
|
- Issue #16983: the new email header parsing code will now decode encoded words
|
||||||
that are (incorrectly) surrounded by quotes, and register a defect.
|
that are (incorrectly) surrounded by quotes, and register a defect.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user