Windows 中默认的 TCP 连接超时是多少?

Windows 中默认的 TCP 连接超时是多少?

Windows 中默认的 TCP 连接超时是多少?有一个注册表项可以配置它还是动态设置的?

答案1

在 Windows 中,该值是动态的已确立的连接,尽管默认为初始连接为 72 秒。注册表设置定义如下:

http://technet.microsoft.com/en-us/library/cc739819(WS.10).aspx

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services:\Tcpip\参数

初始RTT:定义新连接的初始超时设置。每次在连接超时前重新传输时,此数字(以秒为单位)都会翻倍。默认为 3。

TcpMaxConnectRetransmissions:定义在连接超时之前建立连接时重新传输的次数。默认为 2。

答案2

通常,“连接超时”是指创建与主机的初始连接的超时。在许多系统(包括 Windows 7)中,此值是使用与建立连接后持续通信的超时不同的设置配置的。此答案解决了 Windows 7 的“初始连接”场景,这与 XP 不同。

对于 Windows 7,需要两个修补程序来支持调整连接超时设置。可以使用“netsh”命令配置新设置。

来自 2786464 修补程序文章:

注意:在 Windows 7 和 Windows Server 2008 R2 中,TCP 最大 SYN 重新传输 (JH:MaxSynRetransmissions) 值设置为 2,并且不可配置。由于初始超时值 (JH:InitialRTO) 限制为 3 秒,因此 TCP 三次握手限制为 21 秒时间范围(3 秒 + 2*3 秒 + 4*3 秒 = 21 秒)。

第一个修补程序添加了“MaxSynRetransmissions”设置,允许将重试设置从默认值 2 更改。第二个修补程序添加了“InitialRto”设置,允许将初始 RTO 值从默认值 3000ms(是的,毫秒)更改为短于 3000ms 的值;它不能增加。根据您的情况,您可能只需要“MaxSynRetransmissions”修补程序。

安装两个修补程序,重新启动,然后以管理员身份打开命令窗口。后续调用 netsh 命令时无需重新启动。

C:\Windows\system32>NET SESSION >nul 2>&1

C:\Windows\system32>IF %ERRORLEVEL% EQU 0 (ECHO Administrator PRIVILEGES Detected!) ELSE ( ECHO NOT AN ADMIN! )
Administrator PRIVILEGES Detected!

C:\Windows\system32>netsh interface tcp show global
Querying active state...

TCP Global Parameters
----------------------------------------------
Receive-Side Scaling State          : enabled
Chimney Offload State               : automatic
NetDMA State                        : enabled
Direct Cache Acess (DCA)            : disabled
Receive Window Auto-Tuning Level    : normal
Add-On Congestion Control Provider  : none
ECN Capability                      : disabled
RFC 1323 Timestamps                 : disabled
Initial RTO                         : 3000
Non Sack Rtt Resiliency             : disabled
Max SYN Retransmissions             : 2
** The above autotuninglevel setting is the result of Windows Scaling heuristics

overriding any local/policy configuration on at least one profile.

C:\Windows\system32>cmd /v:on /c "echo !TIME! & telnet 192.168.1.254 & echo !TIME!"
14:10:30.53
Connecting To 192.168.1.254...Could not open connection to the host, on port 23: Connect failed
14:10:51.60


C:\Windows\system32>netsh interface tcp set global MaxSynRetransmissions=3
Ok.


C:\Windows\system32>netsh interface tcp show global
Querying active state...

TCP Global Parameters
----------------------------------------------
Receive-Side Scaling State          : enabled
Chimney Offload State               : automatic
NetDMA State                        : enabled
Direct Cache Acess (DCA)            : disabled
Receive Window Auto-Tuning Level    : normal
Add-On Congestion Control Provider  : none
ECN Capability                      : disabled
RFC 1323 Timestamps                 : disabled
Initial RTO                         : 3000
Non Sack Rtt Resiliency             : disabled
Max SYN Retransmissions             : 3
** The above autotuninglevel setting is the result of Windows Scaling heuristics

overriding any local/policy configuration on at least one profile.

C:\Windows\system32>cmd /v:on /c "echo !TIME! & telnet 192.168.1.254 & echo !TIME!"
14:27:02.33
Connecting To 192.168.1.254...Could not open connection to the host, on port 23:
 Connect failed
14:27:47.41

C:\Windows\system32>netsh interface tcp set global MaxSynRetransmissions=2
Ok.


C:\Windows\system32>netsh interface tcp set global InitialRto=1000
Ok.


C:\Windows\system32>netsh interface tcp show global
Querying active state...

TCP Global Parameters
----------------------------------------------
Receive-Side Scaling State          : enabled
Chimney Offload State               : automatic
NetDMA State                        : enabled
Direct Cache Acess (DCA)            : disabled
Receive Window Auto-Tuning Level    : normal
Add-On Congestion Control Provider  : none
ECN Capability                      : disabled
RFC 1323 Timestamps                 : disabled
Initial RTO                         : 1000
Non Sack Rtt Resiliency             : disabled
Max SYN Retransmissions             : 2
** The above autotuninglevel setting is the result of Windows Scaling heuristics

overriding any local/policy configuration on at least one profile.


C:\Windows\system32>cmd /v:on /c "echo !TIME! & telnet 192.168.1.254 & echo !TIME!"
14:29:06.13
Connecting To 192.168.1.254...Could not open connection to the host, on port 23:
 Connect failed
14:29:13.20

注意:实际连接超时以 Windows telnet 为参考。需要单独安装,但操作简单。

附加链接/荣誉:

答案3

TcpInitialRTT 和 TcpMaxConnectRetransmissions 可能不存在于 Vista 和 Windows 2008 中。此 Microsoft 文档未包含它们。 http://download.microsoft.com/download/c/2/6/c26893a6-46c7-4b5c-b287-830216597340/TCPIP_Reg.doc

这至少表明 TcpInitialRTT 已经消失,尽管我不知道它有多可靠。 http://pul.se/Blog-Post-TCP-IP-Stack-hardening-in-Operating-Systems-starting-with-Windows-Vista_SharePoint-kHPTTCP0WJ5,7zq00hH0wINE

答案4

如果我理解正确你的问题,你指的是:

TcpTimedWaitDelay

此键确定 TCP/IP 释放已关闭的连接并重新使用其资源之前必须经过的时间。关闭和释放之间的间隔称为 TIME_WAIT 状态或最大段生存期 (2MSL) 的两倍状态。在此期间,重新打开与客户端和服务器的连接比建立新连接的成本更低。通过降低此条目的值,TCP/IP 可以更快地释放已关闭的连接并为新连接提供更多资源。如果正在运行的应用程序需要快速释放、创建新连接或由于多个连接处于 TIME_WAIT 状态而导致吞吐量低而进行调整,请调整此参数。

确切的键是:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Tcpip\Parameters\TcpTimedWaitDelay

如果您使用的是 Win2008 或更高版本,则可能未设置该值,但默认值为十进制 240(即 240 秒或 4 分钟)。您可以将该键添加到注册表中,并使用不同的值,该值将在重新启动后生效(在生产环境中的 Windows Server 2008R2 上进行了测试)。考虑到现代网络的质量,这是一个高得离谱的值。

不到一个月前,我在服务器上运行了一个应用程序,该应用程序耗尽了 Windows 可以支持的最大连接数,并定期终止该服务器上的所有网络服务。当您甚至设法通过 RDP 连接到服务器时,netstat -a 中有 16,000 多个连接。我们将值设置为 30 进制(30 秒),瞧,问题解决了 - 同时连接数少于 10,000 个(因为应用程序正在快速打开和关闭它们),没有吞吐量问题。

相关内容