Linux tcp_tw_reuse 与 tcp_tw_recycle :使用哪个(或两者)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6426253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:38:43  来源:igfitidea点击:

tcp_tw_reuse vs tcp_tw_recycle : Which to use (or both)?

linuxnetworkingtcp

提问by Michael Marsee

I have a website and application which use a significant number of connections. It normally has about 3,000 connections statically open, and can receive anywhere from 5,000 to 50,000 connection attempts in a few seconds time frame.

我有一个使用大量连接的网站和应用程序。它通常静态打开大约 3,000 个连接,并且可以在几秒钟的时间内接收 5,000 到 50,000 次连接尝试。

I have had the problem of running out of local ports to open new connections due to TIME_WAIT status sockets. Even with tcp_fin_timeout set to a low value (1-5), this seemed to just be causing too much overhead/slowdown, and it would still occasionally be unable to open a new socket.

由于 TIME_WAIT 状态套接字,我遇到了用完本地端口来打开新连接的问题。即使将 tcp_fin_timeout 设置为较低的值 (1-5),这似乎只会导致过多的开销/速度减慢,并且偶尔仍无法打开新套接字。

I've looked at tcp_tw_reuse and tcp_tw_recycle, but I am not sure which of these would be the preferred choice, or if using both of them is an option.

我已经查看了 tcp_tw_reuse 和 tcp_tw_recycle,但我不确定其中哪一个是首选,或者是否可以选择同时使用它们。

回答by Cédric Julien

According to Linux documentation, you should use the TCP_TW_REUSE flag to allow reusing sockets in TIME_WAIT state for new connections.

根据Linux 文档,您应该使用 TCP_TW_REUSE 标志来允许将 TIME_WAIT 状态的套接字重用于新连接。

It seems to be a good option when dealing with a web server that have to handle many short TCP connections left in a TIME_WAIT state.

在处理必须处理许多处于 TIME_WAIT 状态的短 TCP 连接的 Web 服务器时,这似乎是一个不错的选择。

As described here, The TCP_TW_RECYCLE could cause some problems when using load balancers...

如上所述这里,该TCP_TW_RECYCLE可以使用负载均衡器时,会导致一些问题...

EDIT (to add some warnings ;) ):

编辑(添加一些警告;)):

as mentionned in comment by @raittes, the "problems when using load balancers" is about public-facing servers. When recycle is enabled, the server can't distinguish new incoming connections from different clients behind the same NAT device.

正如@raittes 在评论中提到的,“使用负载均衡器时的问题”是关于面向公众的服务器。启用回收后,服务器无法区分来自同一 NAT 设备后面的不同客户端的新传入连接。

回答by pevik

NOTE: net.ipv4.tcp_tw_recyclehas been removedfrom Linux?4.12.

注:net.ipv4.tcp_tw_recycle已被删除?从Linux的4.12。

SOURCE: https://vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux

来源:https: //vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux