apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.43k stars 2.11k forks source link

Connections reuse issue #6308

Closed Alterant-zz closed 4 months ago

Alterant-zz commented 4 months ago

Expected behavior

Connections are reused.

Actual behavior

A lot of connections opened and hangs in the TIME_WAIT state.

Steps to reproduce the problem

In the process of testing of web-application, I encountered the problem of running out of ports (java.net.BindException). So I decided to enable connection reuse.

Enabled the "Use KeepAlive" option in the Http Sampler.

Tried adding "httpclient.reset_state_on_thread_group_iteration=false" to the user.properties file. Also tried to enable the "Same user on each iteration" option in the Thread Group.

Even after these actions, I see a large number of connections in the TIME_WAIT state.

After one minute of single thread test:

TCP    127.0.0.1:30110        127.0.0.1:50871        TIME_WAIT
... (28 connections in TIME_WAIT)
TCP    127.0.0.1:30110        127.0.0.1:50915        TIME_WAIT
TCP    127.0.0.1:30110        127.0.0.1:50916        ESTABLISHED
TCP    127.0.0.1:50915        127.0.0.1:30110        TIME_WAIT
TCP    127.0.0.1:50916        127.0.0.1:30110        ESTABLISHED

With the help of wiremock I can see that keep-alive header is sent: "headers": { "Connection": "keep-alive", "User-Agent": "Apache-HttpClient/4.5.14 (Java/21.0.3)" }

And web-app is also responds appropriately: Keep-Alive: timeout=60 Connection: keep-alive

Web-app is running in docker container.

Http sampler is using HttpClient4 and sending a POST request with json payload.

JMeter Version

5.6.3

Java Version

openjdk version "21.0.3" 2024-04-16 LTS

OS Version

Microsoft Windows [Version 10.0.19045.2846]

Alterant-zz commented 4 months ago

Probably it's a server-side issue with max requests on the same connection (Tomcat's maxKeepAliveRequests) which is 100 by default. Will investigate this.

Alterant-zz commented 4 months ago

It was definitely a server issue. Setting maxKeepAliveRequests on Tomcat fixed the problem. Everything is working as expected.

Just for the info: "Same user on each iteration" option takes precedence over "httpclient.reset_state_on_thread_group_iteration". When it is checked "httpclient.reset_state_on_thread_group_iteration" is ignored. When it is unchecked "httpclient.reset_state_on_thread_group_iteration" is used.