JMeter Load testing - HttpHostConnectException: Connection refused: connect on windows server 2012

Viewed 1157

I am doing Load Testing for my application using JMeter. Load Test is running successfully for 1000 threads without any error on MacBook and Windows 10 systems.

However when I am running on Windows Server 2012, It is running fine 100 threads but when I am increasing threads to 250 or 500, I am getting the following error:

  org.apache.http.conn.HttpHostConnectException: Connect to localhost:8050 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl$JMeterDefaultHttpClientConnectionOperator.connect(HTTPHC4Impl.java:404)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:935)
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:646)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:66)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1296)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1285)
    at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:638)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.base/sun.nio.ch.Net.connect0(Native Method)
    at java.base/sun.nio.ch.Net.connect(Net.java:493)
    at java.base/sun.nio.ch.Net.connect(Net.java:482)
    at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:339)
    at java.base/java.net.Socket.connect(Socket.java:603)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    ... 19 more

I am using Apache Jmeter - 5.4.1.

I have spent an entire day searching for a solution without success. There were many similar issues but none helping my case.

I think some configuration changes are required but don't exactly what.

UPDATE 1

I have updated TCP/IP Registery parameters as well to (but no success):

TcpTimedWaitDelay: REG_DWORD=0x0000001e(30) MaxUserPort:REG_DWORD=0x0000fffe(65534) TcpNumConnections:REG_DWORD=0x00fffffe(1677214)

UPDATE 2

It seems the problem is not with the OS version, but with that specific machine. I installed windows server 2012 on my laptop in a virtual Box and tested it. I sent a request with 500 threads without any error.

Host system spec: 8 GB RAM, 4 CPU, Windows 10
Guest system spec: 4 GB RAM, 2 CPU, windows server 12

UPDATE 3

Screenshot of configurations:

enter image description here

Can anyone help, please? Thank you.

4 Answers

This is more a serverfault question, but you can tune using the following solutions:

  1. In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

TcpMaxDataRetransmissions - Timeout limit of TCP unacknowledged data segments retransmission on actual connection = 5.

  1. Updating ephemeral TCP port range

To change the port range, use this command:

netsh int <ipv4|ipv6> set dynamic <tcp|udp> start=number num=range
  1. Adding shutdown command

because a reboot is required for the TCP stack changes.

Increase Pool Size for Ephemeral TCP Ports

 Get-Item 'HKLM:\System\CurrentControlSet\Services\Tcpip\Parameters' | New-ItemProperty -Name MaxUserPort -Value 65534 -Force | Out-Null
 Get-Item 'HKLM:\System\CurrentControlSet\Services\Tcpip\Parameters' | New-ItemProperty -Name TcpTimedWaitDelay -Value 30 -Force | Out-Null
 Get-Item 'HKLM:\System\CurrentControlSet\Services\Tcpip\Parameters' | New-ItemProperty -Name TcpNumConnections -Value 16777214 -Force | Out-Null
 Get-Item 'HKLM:\System\CurrentControlSet\Services\Tcpip\Parameters' | New-ItemProperty -Name TcpMaxDataRetransmissions -Value 5 -Force | Out-Null
 shutdown -r -t 0

There's a problem between Jmeter and OS, Something like firewall, loadbalancer(if there is), any rule in between which restrict number of requests to the OS because of security.

Check if there is any ddos protection tools on that machine.

Try disabling firewall and test again.

My question is, should you run the load testing and the application at the same server? Resource contention is expected here. E.g. for each request, one or more thread in application needs to be spawned to handle the request.

The network agents like fw, lb, waf etc. should not interfere with the loopback connections. But if you have an anti-virus installed, it may slow down the server and cause the client to fail to connect within the connection timeout period.

You can test it with either increasing the client connect timeout or just disabling the av.

Related