[issue21455] add default backlog to socket.listen()

Charles-François Natali report at bugs.python.org
Tue May 13 06:50:45 CEST 2014


Charles-François Natali added the comment:

>> Py_MIN(SOMAXCONN, 128)
>
> On Windows, it's not the best choice to use this hardcoded limit. socket.SOMAXCONN is 2^31-1.

I don't see what this would bring: 128 *is* a reasonable limit.

> listen() documentation says that Windows chooses a reasonable backlog value for you if you pass SOMAXCONN:
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms739168%28v=vs.85%29.aspx
>
> You should maybe use SOMAXCONN by default on Windows, and Py_MIN(SOMAXCONN, 128) by default on other platforms (UNIX).

Trying to come up with a good heuristic is a lost battle, since it
depends not only on the OS but also the application.  The goal is to
have a default value that works, is large enough to avoid connection
drops in common use cases, and not too large to avoid resource
consumption.

> 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):

In theory we could use net.core.somaxconn sysctl & Co (that's what go
does), but IMO it's overkill.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21455>
_______________________________________


More information about the Python-bugs-list mailing list