标签:
对于这个问题找到的一些资料, 仅供参考:
------------------------------------------------------
Again,使用tcp_tw_reuse和tcp_tw_recycle来解决TIME_WAIT的问题是非常非常危险的,因为这两个参数违反了TCP协议(RFC 1122)
其实,TIME_WAIT表示的是你主动断连接,所以,这就是所谓的“不作死不会死”。试想,如果让对端断连接,那么这个破问题就是对方的了,呵呵。另外,如果你的服务器是于HTTP服务器,那么设置一个HTTP的KeepAlive有多重要(浏览器会重用一个TCP连接来处理多个HTTP请求),然后让客户端去断链接(你要小心,浏览器可能会非常贪婪,他们不到万不得已不会主动断连接)。
来源:TCP 的那些事儿(上)
------------------------------------------------------
By default, when both tcp_tw_reuse
and tcp_tw_recycle
are disabled, the kernel will make sure that sockets in TIME_WAIT
state will remain in that state long enough -- long enough to be sure that packets belonging to future connections will not be mistaken for late packets of the old connection.
When you enable tcp_tw_reuse
, sockets in TIME_WAIT
state can be used before they expire, and the kernel will try to make sure that there is no collision regarding TCP sequence numbers. If you enable tcp_timestamps
(a.k.a. PAWS, for Protection Against Wrapped Sequence Numbers), it will make sure that those collisions cannot happen. However, you need TCP timestamps to be enabled on both ends (at least, that‘s my understanding). See the definition of tcp_twsk_unique for the gory details.
When you enable tcp_tw_recycle
, the kernel becomes much more aggressive, and will make assumptions on the timestamps used by remote hosts. It will track the last timestamp used by each remote host having a connection in TIME_WAIT
state), and allow to re-use a socket if the timestamp has correctly increased. However, if the timestamp used by the host changes (i.e. warps back in time), the SYN
packet will be silently dropped, and the connection won‘t establish (you will see an error similar to "connect timeout"). If you want to dive into kernel code, the definition of tcp_timewait_state_process might be a good starting point.
Now, timestamps should never go back in time; unless:
TIME_WAIT
socket will probably have expired, so it will be a non issue);TIME_WAIT
connections will stay a bit, but other connections will probably be struck by TCP RST
and that will free up some space);In the latter case, you can have multiple hosts behind the same IP address, and therefore, different sequences of timestamps (or, said timestamps are randomized at each connection by the firewall). In that case, some hosts will be randomly unable to connect, because they are mapped to a port for which the TIME_WAIT
bucket of the server has a newer timestamp. That‘s why the docs tell you that "NAT devices or load balancers may start drop frames because of the setting".
Some people recommend to leave tcp_tw_recycle
alone, but enable tcp_tw_reuse
and lower tcp_timewait_len
. I concur :-)
来源:Dropping of connections with tcp_tw_recycle
------------------------------------------------------
未看滴:
http://serverfault.com/questions/329845/how-to-forcibly-close-a-socket-in-time-wait
http://www.fromdual.com/huge-amount-of-time-wait-connections
http://stackoverflow.com/questions/26019164/too-many-time-wait-connections-getting-cannot-assign-requested-address
TIME_WAIT与tcp_tw_reuse /tcp_tw_recycle, 开还是不开?
标签:
原文地址:http://www.cnblogs.com/luikimfai/p/4629495.html