linux net.core.somaxconn,Nginx 性能优化之net.core.somaxconn

本文讨论了Linux内核参数net.core.somaxconn对Nginx等web应用性能的影响。默认的128可能导致连接超时或重传,而增大该值并调整Nginx配置可以显著降低错误率,提高并发处理能力。实验结果显示,将net.core.somaxconn设置为8192并配置Nginx监听队列后,错误率降至0,性能得到提升。
摘要由CSDN通过智能技术生成

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,在高突发的请求中可能会导致链接超时或者触发

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值