开始时应做的一件事是修复.NET net.ipv4.tcp_fin_timeout=1
。那是降低的方法,您可能不应该将其降低到30以下。
由于这是nginx的背后。这是否意味着nginx充当反向代理?如果是这种情况,则您的连接是2倍(一个到客户端,一个到您的Web服务器)。您知道这些插座属于哪一端吗?
更新:
fin_timeout是它们在FIN-WAIT-2中停留的时间(来自networking/ip-sysctl.txt
内核文档):
tcp_fin_timeout - INTEGER
Time to hold socket in state FIN-WAIT-2, if it was closed
by our side. Peer can be broken and never close its side,
or even died unexpectedly. Default value is 60sec.
Usual value used in 2.2 was 180 seconds, you may restore
it, but remember that if your machine is even underloaded WEB server,
you risk to overflow memory with kilotons of dead sockets,
FIN-WAIT-2 sockets are less dangerous than FIN-WAIT-1,
because they eat maximum 1.5K of memory, but they tend
to live longer. Cf. tcp_max_orphans.
我认为您可能只需要让Linux保持TIME_WAIT套接字号与它们上的32k上限相抵,这就是Linux回收它们的地方。此链接中提到了32k :
另外,我发现/ proc / sys / net / ipv4 / tcp_max_tw_buckets令人困惑。尽管默认设置为180000,但无论系统上有两个最大存储桶,当系统上有32K TIME_WAIT套接字时,我都会看到TCP中断。
此链接还建议TIME_WAIT状态为60秒,不能通过proc进行调整。
随机有趣的事实:
您可以使用netstat在timewait上看到每个套接字的计时器,netstat -on | grep TIME_WAIT | less
Reuse Vs Recycle:
这很有趣,它看起来像重用,启用了time_Wait套接字的重用,并且将其重设为TURBO模式:
tcp_tw_recycle - BOOLEAN
Enable fast recycling TIME-WAIT sockets. Default value is 0.
It should not be changed without advice/request of technical
experts.
tcp_tw_reuse - BOOLEAN
Allow to reuse TIME-WAIT sockets for new connections when it is
safe from protocol viewpoint. Default value is 0.
It should not be changed without advice/request of technical
experts.
我不建议使用net.ipv4.tcp_tw_recycle,因为它会导致NAT客户端出现问题。
也许您可能不尝试同时打开这两个功能,然后查看其效果(一次尝试一个,看看它们如何独立工作)?我会使用netstat -n | grep TIME_WAIT | wc -l
比Munin更快的反馈。