-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use TCP_NODELAY on the server socket #3008
Conversation
6c9beb3
to
3d678f0
Compare
Sure, why not. We already have our own buffer, so Nagle's algorithm doesn't really benefit us anyway. Could you set TCP_NODELAY on the peer sockets as well? |
pynicotine/slskproto.py
Outdated
@@ -1214,6 +1214,9 @@ def _init_server_conn(self, msg_obj): | |||
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.SOCKET_READ_BUFFER_SIZE) | |||
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, self.SOCKET_WRITE_BUFFER_SIZE) | |||
|
|||
if hasattr(socket, "TCP_NODELAY"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe TCP_NODELAY should be available on every OS we support. Do you know one that doesn't have it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not aware of any without it. I was just copying the safety checks in
nicotine-plus/pynicotine/slskproto.py
Lines 1144 to 1177 in 5ecf2df
if hasattr(socket, "SO_KEEPALIVE"): | |
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # pylint: disable=no-member | |
if hasattr(socket, "TCP_KEEPINTVL"): | |
server_socket.setsockopt(socket.IPPROTO_TCP, | |
socket.TCP_KEEPINTVL, interval) # pylint: disable=no-member | |
if hasattr(socket, "TCP_KEEPCNT"): | |
server_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, count) # pylint: disable=no-member | |
if hasattr(socket, "TCP_KEEPIDLE"): | |
server_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, idle) # pylint: disable=no-member | |
elif hasattr(socket, "TCP_KEEPALIVE"): | |
# macOS fallback | |
server_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, idle) # pylint: disable=no-member | |
elif hasattr(socket, "SIO_KEEPALIVE_VALS"): | |
# Windows fallback | |
# Probe count is set to 10 on a system level, and can't be modified. | |
# https://docs.microsoft.com/en-us/windows/win32/winsock/so-keepalive | |
server_socket.ioctl( | |
socket.SIO_KEEPALIVE_VALS, # pylint: disable=no-member | |
( | |
1, | |
idle * 1000, | |
interval * 1000 | |
) | |
) | |
if hasattr(socket, "TCP_USER_TIMEOUT"): | |
server_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, timeout_seconds * 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leave the check out for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CPython code itself checks for the corresponding C define: https://github.com/python/cpython/blob/7e894c2f38f64aed9b259c8fd31880f1142a259d/Modules/socketmodule.c#L8561
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we should leave all the if hasattr(socket, "TCP_NODELAY"):
checks out for now, because it is probably not required.
It can be added again if any testers report a Critical Error thown by the exception handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Check removed.
No. Those are UDP. |
The Soulseek protocol uses TCP, not UDP. Peer sockets are created here: nicotine-plus/pynicotine/slskproto.py Line 1710 in f8ecc7b
and here: nicotine-plus/pynicotine/slskproto.py Line 2386 in f8ecc7b
|
I stand corrected. Also added for peer sockets. |
Rationale: https://news.ycombinator.com/item?id=40310896