Measuring the Listen Queue
December 01, 2017
Run the command:
netstat -Lan
The command output may be the following:
Current listen queue sizes (qlen/incqlen/maxqlen)
Proto Listen Local Address
tcp46 1863/0/32768 *.80
tcp4 0/0/128 *.31025
tcp6 0/0/128 *.31025
Some tcp sockets may have been deleted.
unix 0/0/32768 /var/run/immortal/tuip/immortal.sock
unix 0/0/255 /var/db/syslog-ng.ctl
unix 0/0/4 /var/run/devd.pipe
unix 0/0/4 /var/run/devd.seqpacket.pipe
The command output shows that there are 1863 unaccepted connections in the listen queue on Port 80, while the connection limit is 32768 connections, and this situation is normal.
However, the command output may be as follows:
Current listen queue sizes (qlen/incqlen/maxqlen)
Listen Local Address
0/0/128 *.12345
192/0/128 *.80
0/0/128 *.8080
The command output shows 192 unaccepted connections which exceeds the limit of 128 connections. This is quite common when a web site experience heavy traffic.
🔗Tuning the Operating System
Increase the value of the somaxconn
key from its default value (128)
to the value high enough to be able to handle a high burst of traffic:
For FreeBSD:
sysctl kern.ipc.somaxconn=4096
For Linux:
sudo sysctl -w net.core.somaxconn=4096
🔗Tuning NGINX
If you set the somaxconn key to a value greater than 512, change the backlog parameter of the NGINX listen directive to match:
server {
listen 80 backlog=4096;
# The rest of server configuration
}
See also:
- Time Wait
- https://www.nginx.com/resources/admin-guide/serving-static-content/