What is “backlog” in TCP connections?

后端 未结 3 1291
走了就别回头了
走了就别回头了 2020-12-13 00:30

Below, you see a python program that acts as a server listening for connection requests to port 9999:

# server.py 
import socket                             


        
3条回答
  •  孤街浪徒
    2020-12-13 01:08

    When TCP connection is being established the so called three-way handshake is performed. Both sides exchange some packets and once they do it this connection is called complete and it is ready to be used by the application.

    However this three-way handshake takes some time. And during that time the connection is queued and this is the backlog. So you can set the maximum amount of incomplete parallel connections via .listen(no) call (note that according to the posix standard the value is only a hint, it may be totally ignored). If someone tries to establish a connection above backlog limit the other side will refuse it.

    So the backlog limit is about pending connections, not established.

    Now higher backlog limit will be better in most cases. Note that the maximum limit is OS dependent, e.g. cat /proc/sys/net/core/somaxconn gives me 128 on my Ubuntu.

提交回复
热议问题