web应用中listen函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值。如:
net.core.netdev_max_backlog = 262144
我们线上服务器net.core.somaxconn都是默认的128,这个参数会影响到所有AF_INET类型socket的listen队列
Man 2 listen可以知道:
int listen(int s, int backlog);
The backlog parameter defines the maximum length the queue of pending connections may grow to. If a connection request
arrives with the queue full the client may receive an error with an indication of ECONNREFUSED or, if the underlying pro-
tocol supports retransmission, the request may be ignored so that retries succeed.
BUGS
If the socket is of type AF_INET, and the backlog argument is greater than the constant SOMAXCONN (128 in Linux 2.0 &
2.2), it is silently truncated to SOMAXCONN.
也就是说,web应用中listen函数的backlog会给我们内核参数的net.core.somaxconn 限制到128,在高突发的请求中可能会导致链接超时或者触发