New submission from STINNER Victor <vstin...@python.org>:

Currently, socket.socket.listen() called with no argument limits the default 
backlog to 128:

    /* We try to choose a default backlog high enough to avoid connection drops
     * for common workloads, yet not too high to limit resource usage. */
    int backlog = Py_MIN(SOMAXCONN, 128);

I just saw an article suggesting to use 4096 instead:
https://blog.cloudflare.com/syn-packet-handling-in-the-wild/

On my Fedora 30, listen() manual page says:

       The  behavior of the backlog argument on TCP sockets changed with Linux
       2.2.  Now it specifies the  queue  length  for  completely  established
       sockets  waiting  to  be  accepted, instead of the number of incomplete
       connection requests.  The maximum length of the  queue  for  incomplete
       sockets  can be set using /proc/sys/net/ipv4/tcp_max_syn_backlog.  When
       syncookies are enabled there is no logical maximum length and this set‐
       ting is ignored.  See tcp(7) for more information.

       If    the   backlog   argument   is   greater   than   the   value   in
       /proc/sys/net/core/somaxconn, then it is  silently  truncated  to  that
       value;  the  default  value  in  this  file  is 128.  In kernels before
       2.4.25, this limit was a hard coded value, SOMAXCONN,  with  the  value
       128.

Python 3.8 new socket.create_server() calls sock.listen() by default: so use 
Py_MIN(SOMAXCONN, 128) by default.

----------
components: Library (Lib)
messages: 356037
nosy: giampaolo.rodola, vstinner
priority: normal
severity: normal
status: open
title: socket: change listen() default backlog from 128 to 4096?
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38699>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to