Linux – How to monitor the length of the accept queue

linuxmonitoringnetworking

I have a hypothesis: sometimes TCP connections arrive faster than my server can accept() them. They queue up until the queue overflows and then there are problems.

How can I confirm this is happening?

Can I monitor the length of the accept queue or the number of overflows? Is there a counter exposed somewhere?

Best Answer

To check if your queue is overflowing use either netstat or nstat

[centos ~]$ nstat -az | grep -i listen
TcpExtListenOverflows           3518352            0.0
TcpExtListenDrops               3518388            0.0
TcpExtTCPFastOpenListenOverflow 0  0.0

[centos ~]$ netstat -s | grep -i LISTEN
    3518352 times the listen queue of a socket overflowed
    3518388 SYNs to LISTEN sockets dropped

Reference: https://perfchron.com/2015/12/26/investigating-linux-network-issues-with-netstat-and-nstat/

To monitor your queue sizes, use the ss command and look for SYN-RECV sockets.

$ ss -n state syn-recv sport = :80 | wc -l
119

Reference: https://blog.cloudflare.com/syn-packet-handling-in-the-wild/

Related Question