场景:用JMeter做压力测试的时候,一段时间后Aggregate Report报告里的错误率就一直上升,查看View Results Tree报告时发现报如下错误:
Response code:Non HTTP response code: java.net.BindException
Response message:Non HTTP response message: Address already in use: connect
这个是因为发送HTTP请求时需要为TCP/IP连接分配一个临时端口,客户端关闭连接后,连接会有60s时间处于等待状态。JMeter做压测时每秒发送数千个HTTP请求,系统会耗尽可供分配的临时端口造成临时端口不够用,可以在注册表里设置一下解决这个报错。
1. 问题原因描述:(网上找来的)
When an HTTP request is made, an ephemeral port is allocated for the TCP / IP connection. The ephemeral port range is 32678 – 61000. After the client closes the connection, the connection is placed in the TIME-WAIT state for 60 seconds.
If JMeter (HttpClient) is sending thousands of HTTP requests per second and creating new TCP / IP connections, the system will run out of available ephemeral ports for allocation.
Otherwise, the following messages may appear in the JMeter JTL files:
Non HTTP response code: java.net.BindException Non HTTP response message: Address already in use
The solution is to enable fast recycling TIME_WAIT sockets.
2. 具体修改注册表如下:
进入注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters,右键新建如下2项:
右键New->DWORD (32-bit) Value, 名称输入:TcpTimedWaitDelay,修改值为30(十进制),如下图所示。设置等待时间为30s。
?右键New->DWORD (32-bit) Value, 名称输入:MaxUserPort,修改值为65534(十进制),如下图所示。设置最大连接数为65534。
?设置完成后重启电脑。再使用JMeter测试之前的脚本就不会再报此错误。
|