tcp_tw_recycle别随便开

当我们发现服务端TIME_WAIT状态连接数太多你会怎么办?是不是也是拿起那版斧头,三下五除二的将内核参数优化一下,开启了tcp_tw_recycle用于TIME_WAIT的快速回收。

#vi /etc/sysctl.conf

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

RFC1323 It is described in the following paragraph :

An additional mechanism could be added to the TCP, a per-hostcache of the last timestamp received from any connection.This value could then be used in thePAWSmechanism to rejectold duplicate segments from earlier incarnations of theconnection, if the timestamp clock can be guaranteed to haveticked at least once since the old connection was open. Thiswould require that the TIME-WAIT delay plus the RTT togethermust be at least one tick of the sender’s timestamp clock.Such an extension is not part of the proposal of this RFC.

Probably means to say TCP There is an act , You can cache the latest timestamp of each connection , In subsequent requests, if the timestamp is less than the cached timestamp , It is considered invalid , The corresponding packet will be discarded .

Linux Whether to enable this behavior depends on tcp_timestamps and tcp_tw_recycle, because tcp_timestamps The default is on , So when tcp_tw_recycle When it's turned on , In fact, this behavior is activated .

Linux是否启用这种行为取决于tcp_timestamps和tcp_tw_recycle,因为tcp_timestamps缺省就是开启的,所以当tcp_tw_recycle被开启后,实际上这种行为就被激活了。


netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

你可能感兴趣的:(tcp_tw_recycle别随便开)