[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5 (issue #27456)

yury.selivanov python-checkins at python.org
Sun Sep 11 21:44:06 EDT 2016


https://hg.python.org/cpython/rev/10384c5c18f5
changeset: 103675:10384c5c18f5
parent: 103673:681096fb4aac
parent: 103674:3f7e4ae9eba3
user: Yury Selivanov <yury at magic.io>
date: Sun Sep 11 21:44:17 2016 -0400
summary:
 Merge 3.5 (issue #27456)
files:
 Lib/asyncio/selector_events.py | 16 ++++++++++++++++
 Misc/NEWS | 2 ++
 2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -39,6 +39,17 @@
 return bool(key.events & event)
 
 
+if hasattr(socket, 'TCP_NODELAY'):
+ def _set_nodelay(sock):
+ if (sock.family in {socket.AF_INET, socket.AF_INET6} and
+ sock.type == socket.SOCK_STREAM and
+ sock.proto == socket.IPPROTO_TCP):
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+else:
+ def _set_nodelay(sock):
+ pass
+
+
 class BaseSelectorEventLoop(base_events.BaseEventLoop):
 """Selector event loop.
 
@@ -641,6 +652,11 @@
 self._eof = False
 self._paused = False
 
+ # Disable the Nagle algorithm -- small writes will be
+ # sent without waiting for the TCP ACK. This generally
+ # decreases the latency (in some cases significantly.)
+ _set_nodelay(self._sock)
+
 self._loop.call_soon(self._protocol.connection_made, self)
 # only start reading when connection_made() has been called
 self._loop.call_soon(self._loop.add_reader,
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -365,6 +365,8 @@
 
 - asyncio: Add set_protocol / get_protocol to Transports.
 
+- Issue #27456: asyncio: Set TCP_NODELAY by default.
+
 IDLE
 ----
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /