调整 Windows 参数

对于 Windows 平台,默认 TCP/IP 设置通常就足够了。不过,在负载过重的情况下,可能有必要调整 MaxUserPortTcpTimedWaitDelay。这些参数确定应用程序请求的用户端口的可用性。

参数 默认值 建议值
TcpTimedWaitDelay

此参数控制 OS 在应用程序关闭 TCP 连接后回收端口所等待的时间。默认值为 4 分钟。在用户负载过重时,可能会超出这些限制,从而导致“地址正在使用”连接异常。

在 Windows 注册表的以下位置设置此参数:HKLM\System\CurrentControlSet\Services\Tcpip\Parameters

值名称:TcpTimedWaitDelay

值类型:DWORD

数据:30(十进制)

240 30

MaxUserPort

值名称:MaxUserPort

值类型:DWORD

数据:65534(十进制)

从 Windows2008 开始,需要执行以下命令才能设置上述数量的端口:

netsh int ipv4 set dynamicportrange protocol=tcp startport=10100 numberofports=55433 store=persistent

上面提供的命令是基于 support.microsoft.com 中的以下文章:

动态端口范围

Windows 设置

5000 65534