Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3bc0ebab
Commit
3bc0ebab
authored
Dec 03, 2018
by
Andrew Svetlov
Committed by
GitHub
Dec 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-35380: Enable TCP_NODELAY for proactor event loop (#10867)
parent
3bb150d8
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
42 deletions
+45
-42
Lib/asyncio/base_events.py
Lib/asyncio/base_events.py
+11
-0
Lib/asyncio/proactor_events.py
Lib/asyncio/proactor_events.py
+5
-1
Lib/asyncio/selector_events.py
Lib/asyncio/selector_events.py
+1
-12
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_base_events.py
+27
-3
Lib/test/test_asyncio/test_selector_events.py
Lib/test/test_asyncio/test_selector_events.py
+0
-26
Misc/NEWS.d/next/Library/2018-12-03-14-41-11.bpo-35380.SdRF9l.rst
...S.d/next/Library/2018-12-03-14-41-11.bpo-35380.SdRF9l.rst
+1
-0
No files found.
Lib/asyncio/base_events.py
View file @
3bc0ebab
...
@@ -168,6 +168,17 @@ def _run_until_complete_cb(fut):
...
@@ -168,6 +168,17 @@ def _run_until_complete_cb(fut):
futures
.
_get_loop
(
fut
).
stop
()
futures
.
_get_loop
(
fut
).
stop
()
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
_SendfileFallbackProtocol
(
protocols
.
Protocol
):
class
_SendfileFallbackProtocol
(
protocols
.
Protocol
):
def
__init__
(
self
,
transp
):
def
__init__
(
self
,
transp
):
if
not
isinstance
(
transp
,
transports
.
_FlowControlMixin
):
if
not
isinstance
(
transp
,
transports
.
_FlowControlMixin
):
...
...
Lib/asyncio/proactor_events.py
View file @
3bc0ebab
...
@@ -13,7 +13,6 @@ import warnings
...
@@ -13,7 +13,6 @@ import warnings
from
.
import
base_events
from
.
import
base_events
from
.
import
constants
from
.
import
constants
from
.
import
events
from
.
import
futures
from
.
import
futures
from
.
import
exceptions
from
.
import
exceptions
from
.
import
protocols
from
.
import
protocols
...
@@ -445,6 +444,11 @@ class _ProactorSocketTransport(_ProactorReadPipeTransport,
...
@@ -445,6 +444,11 @@ class _ProactorSocketTransport(_ProactorReadPipeTransport,
_sendfile_compatible
=
constants
.
_SendfileMode
.
TRY_NATIVE
_sendfile_compatible
=
constants
.
_SendfileMode
.
TRY_NATIVE
def
__init__
(
self
,
loop
,
sock
,
protocol
,
waiter
=
None
,
extra
=
None
,
server
=
None
):
super
().
__init__
(
loop
,
sock
,
protocol
,
waiter
,
extra
,
server
)
base_events
.
_set_nodelay
(
sock
)
def
_set_extra
(
self
,
sock
):
def
_set_extra
(
self
,
sock
):
self
.
_extra
[
'socket'
]
=
sock
self
.
_extra
[
'socket'
]
=
sock
...
...
Lib/asyncio/selector_events.py
View file @
3bc0ebab
...
@@ -39,17 +39,6 @@ def _test_selector_event(selector, fd, event):
...
@@ -39,17 +39,6 @@ def _test_selector_event(selector, fd, event):
return
bool
(
key
.
events
&
event
)
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
):
class
BaseSelectorEventLoop
(
base_events
.
BaseEventLoop
):
"""Selector event loop.
"""Selector event loop.
...
@@ -742,7 +731,7 @@ class _SelectorSocketTransport(_SelectorTransport):
...
@@ -742,7 +731,7 @@ class _SelectorSocketTransport(_SelectorTransport):
# Disable the Nagle algorithm -- small writes will be
# Disable the Nagle algorithm -- small writes will be
# sent without waiting for the TCP ACK. This generally
# sent without waiting for the TCP ACK. This generally
# decreases the latency (in some cases significantly.)
# decreases the latency (in some cases significantly.)
_set_nodelay
(
self
.
_sock
)
base_events
.
_set_nodelay
(
self
.
_sock
)
self
.
_loop
.
call_soon
(
self
.
_protocol
.
connection_made
,
self
)
self
.
_loop
.
call_soon
(
self
.
_protocol
.
connection_made
,
self
)
# only start reading when connection_made() has been called
# only start reading when connection_made() has been called
...
...
Lib/test/test_asyncio/test_base_events.py
View file @
3bc0ebab
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import
concurrent.futures
import
concurrent.futures
import
errno
import
errno
import
logging
import
math
import
math
import
os
import
os
import
socket
import
socket
...
@@ -15,7 +14,6 @@ from unittest import mock
...
@@ -15,7 +14,6 @@ from unittest import mock
import
asyncio
import
asyncio
from
asyncio
import
base_events
from
asyncio
import
base_events
from
asyncio
import
constants
from
asyncio
import
constants
from
asyncio
import
events
from
test.test_asyncio
import
utils
as
test_utils
from
test.test_asyncio
import
utils
as
test_utils
from
test
import
support
from
test
import
support
from
test.support.script_helper
import
assert_python_ok
from
test.support.script_helper
import
assert_python_ok
...
@@ -2075,5 +2073,31 @@ class BaseLoopSockSendfileTests(test_utils.TestCase):
...
@@ -2075,5 +2073,31 @@ class BaseLoopSockSendfileTests(test_utils.TestCase):
self
.
run_loop
(
self
.
loop
.
sock_sendfile
(
sock
,
self
.
file
,
-
1
))
self
.
run_loop
(
self
.
loop
.
sock_sendfile
(
sock
,
self
.
file
,
-
1
))
class
TestSelectorUtils
(
test_utils
.
TestCase
):
def
check_set_nodelay
(
self
,
sock
):
opt
=
sock
.
getsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
)
self
.
assertFalse
(
opt
)
base_events
.
_set_nodelay
(
sock
)
opt
=
sock
.
getsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
)
self
.
assertTrue
(
opt
)
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'TCP_NODELAY'
),
'need socket.TCP_NODELAY'
)
def
test_set_nodelay
(
self
):
sock
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
socket
.
IPPROTO_TCP
)
with
sock
:
self
.
check_set_nodelay
(
sock
)
sock
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
socket
.
IPPROTO_TCP
)
with
sock
:
sock
.
setblocking
(
False
)
self
.
check_set_nodelay
(
sock
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Lib/test/test_asyncio/test_selector_events.py
View file @
3bc0ebab
...
@@ -14,7 +14,6 @@ from asyncio.selector_events import BaseSelectorEventLoop
...
@@ -14,7 +14,6 @@ from asyncio.selector_events import BaseSelectorEventLoop
from
asyncio.selector_events
import
_SelectorTransport
from
asyncio.selector_events
import
_SelectorTransport
from
asyncio.selector_events
import
_SelectorSocketTransport
from
asyncio.selector_events
import
_SelectorSocketTransport
from
asyncio.selector_events
import
_SelectorDatagramTransport
from
asyncio.selector_events
import
_SelectorDatagramTransport
from
asyncio.selector_events
import
_set_nodelay
from
test.test_asyncio
import
utils
as
test_utils
from
test.test_asyncio
import
utils
as
test_utils
...
@@ -1344,30 +1343,5 @@ class SelectorDatagramTransportTests(test_utils.TestCase):
...
@@ -1344,30 +1343,5 @@ class SelectorDatagramTransportTests(test_utils.TestCase):
exc_info
=
(
ConnectionRefusedError
,
MOCK_ANY
,
MOCK_ANY
))
exc_info
=
(
ConnectionRefusedError
,
MOCK_ANY
,
MOCK_ANY
))
class
TestSelectorUtils
(
test_utils
.
TestCase
):
def
check_set_nodelay
(
self
,
sock
):
opt
=
sock
.
getsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
)
self
.
assertFalse
(
opt
)
_set_nodelay
(
sock
)
opt
=
sock
.
getsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
)
self
.
assertTrue
(
opt
)
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'TCP_NODELAY'
),
'need socket.TCP_NODELAY'
)
def
test_set_nodelay
(
self
):
sock
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
socket
.
IPPROTO_TCP
)
with
sock
:
self
.
check_set_nodelay
(
sock
)
sock
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
socket
.
IPPROTO_TCP
)
with
sock
:
sock
.
setblocking
(
False
)
self
.
check_set_nodelay
(
sock
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Misc/NEWS.d/next/Library/2018-12-03-14-41-11.bpo-35380.SdRF9l.rst
0 → 100644
View file @
3bc0ebab
Enable TCP_NODELAY on Windows for proactor asyncio event loop.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment