sysctl.si › Parameters › net.core.somaxconn
net.core.somaxconn
Longest queue of finished connections waiting for accept().
- Default
- 4096 (128 before 5.4)
- Typical value
- 4096 to 65535
When to change it
Raise it for busy listeners such as nginx or HAProxy. The application's own backlog setting must also be raised to benefit.
How it works
When a server calls listen(), the kernel keeps a queue of connections that have finished the TCP handshake but have not yet been accepted by the application. net.core.somaxconn is the largest queue length the kernel allows.
The effective queue is the smaller of this value and the backlog the application asks for. Kernels before 5.4 default to 128, and newer ones default to 4096.
Signs you need to change it
- Clients see timeouts or resets during traffic bursts while CPU use is low.
- nstat -az TcpExtListenOverflows or netstat -s shows the listen queue overflowing.
- ss -lnt shows a listening socket whose Recv-Q is close to its Send-Q.
Recommended values by workload
- Small service, light traffic
- 4096 (default on modern kernels)
- Busy web server or proxy
- 16384
- Very high connection rates
- 65535
Common mistakes
- Raising the kernel value but not the application backlog, for example in nginx, HAProxy or Redis.
- Ignoring the SYN queue. For bursts of new connections also review net.ipv4.tcp_max_syn_backlog.
- In Kubernetes, expecting a pod to set it without permission. It is an unsafe sysctl, so the kubelet must allow it.
Check the current value
sysctl net.core.somaxconn
Change it until the next reboot
sudo sysctl -w net.core.somaxconn=4096
Make it permanent
echo "net.core.somaxconn = 4096" | sudo tee /etc/sysctl.d/99-custom.conf sudo sysctl --system
Related parameters
net.ipv4.tcp_max_syn_backlog · net.core.netdev_max_backlog · net.core.rmem_max · net.core.wmem_max · net.ipv4.tcp_congestion_control · net.core.default_qdisc · net.ipv4.tcp_tw_reuse · net.ipv4.tcp_fin_timeout
Generate a full sysctl config for your server
Values are starting points. Test on a staging machine and measure before and after.