JMeter and Controlling HTTP Keepalives

jmeterThreading and keepalives in HTTP are always an issue in performance testing and testing tools. When does a keepalive session start and how many are started is a thing of mystery. So having a bit of clarity helps. On my current project I wanted to prove what thread connects to what server for how long.

In order to be able to do that I had to get our F5 to insert the server name from the answering web server into the response header (e.g. “Server: Web Server 1”). This can also be done web-server side. So it should be possible in most environments.

The JMeter script then has to decode the response header and print the result to the jmeter.log. In order to see what thread goes where we also need to add the thread name/number to the output. The easiest way to do that would be in a BeanShell post processor. So the code I used looks like this:

String str = prev.getResponseHeaders(); 
String thr = prev.getThreadName();
String [] line = str.split("\n");
log.info(thr + " ; " + line[5]);

You can add this to as many HTTP requests as you like. If you attach it to several in a flow it might also be good to add the actual URL or title so you can distinguish between the calls. Please also adjust the line number (highlight in red above) to correctly identify the header response line you want. If needed you can also dump the full header but that will generate a lot of data.

Once this is done you can filter the jmeter.log file and process it with your method of choice to figure out how your keepalives work.

So… in the end I did find out that the script I was using would not reset the connection after the thread loop was finished (Please note that in the JMeter script I used the HTTP calls had the keepalives check-box ticked). That means if I’d run ten threads that would mean 10 connections were opened and re-used constantly. When I ran the script with the last HTTP request’s keepalives check-box disabled it would react as I wanted. It would use keepalives during the flow (from login to logout) and then abandon/close the connection.

This was tested on Ubuntu 14.04 with Java 1.6 and JMeter 2.11.

by Oliver Erlewein

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s