-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
add default backlog to socket.listen() #65654
Comments
Having to pass an explicit backlog value to listen() is a pain: most people don't know which value to pass, and often end up using a value too small which can lead to connections being rejected. The patch attached uses a default value of SOMAXCONN for socket.listen(): it should give a good default behavior (that's what golang does for example: in fact they go even further by checking the runtime value from net.core.somaxconn). A second step would be to update the codebase to remove explicit backlogs (unless specific case). |
Is there a risk of SOMAXCONN being huge and therefore allocating a large amount of resources? |
On a sensible operating system, no, but better safe than sorry: the |
Any objection to the last version? If not, I'll commit it within a few days. |
Looks good to me! |
On Windows, it's not the best choice to use this hardcoded limit. socket.SOMAXCONN is 2^31-1. listen() documentation says that Windows chooses a reasonable backlog value for you if you pass SOMAXCONN: You should maybe use SOMAXCONN by default on Windows, and Py_MIN(SOMAXCONN, 128) by default on other platforms (UNIX). |
An article suggests to use max(1024, socket.SOMAXCONN) (to "listen() backlog as large as possible") instead of socket.SOMAXCONN because the OS maximum can be larger than SOMAXCONN (and that it's not possible in Python to get the OS value): The following article tries to explain why the default limit is 128 on Linux: Article giving the value chosen by Windows when SOMAXCONN is passed: it depends on the Windows version (between 5 and 50, hard limit of 200 on Windows 7): |
I don't see what this would bring: 128 *is* a reasonable limit.
Trying to come up with a good heuristic is a lost battle, since it
In theory we could use net.core.somaxconn sysctl & Co (that's what go |
Hum ok, thanks for your explanation Charles-François. socket_listen-1.diff looks good to me. |
New changeset 09371221e59d by Charles-François Natali in branch 'default': |
Committed, thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: