Configure JMeter to Handle Dynamic IPs and Loadbalancer

Do you see errors in JMeter while executing the performance testing, but not see such errors if you access the website manually during the load testing? If yes, then, there is a possibility you have not properly configured your JMeter script. Let’s configure JMeter to Handle Dynamic IPs and Loadbalancer before putting the load on such website.

This will paint your report red which no one wants as these errors are not related to the Application Under Test (AUT).

If JMeter is not configured properly for such a website then, you may observe the following:

  1. The requests are getting redirected to only one server and the other server is sitting idle while doing the load testing of the website that has multiple servers to balance the requests using a load balancer.
  2. Errors like “Target server failed to respond” or “Your hostname could not be resolved to an IP address” in JMeter or “java.net.SocketException: Software caused connection abort recv failed”

Here is how the results will look like. See below screenshot and the response data.

Errors due to DNS caching

There are several reasons for this problem like insufficient hardware or generating unrealistic load, but if you think you are generating realistic load using decent hardware, but still getting those error then, Java DNS caching could causing the problem.

DNS Caching problem occurs if there is:

  • a load balancer (for example, CDN)
  • or, IPs are dynamic (for example, services hosted on AWS)

Solution

  1. Change the TTL, Java DNS Cache settings
  2. Or, add DNS Cache Manager in JMeter (from JMeter 2.12 the DNS Cache Manager has been included as a configuration element)

Before looking into the solution let us see, how is Java DNS caching related to this problem?

What Java does is, it caches the IP address against each domain name you access and the JVM default TTL is set to never re-resolve DNS names to IP addresses. This means that when the IP address for  resource changes, the application will be unable to connect to that resource until someone manually restarts the JVM so that the new IP addresses can be picked up. In these cases, it is vital that the TTL be configured to a shorter time period, like 60 seconds.

Option 1:

You can configure the TTL in the file java.security, which is located in the directory %JRE%libsecurity. The configured value specifies the number of seconds that the JVM should cache a successful DNS name lookup. Here is an example that shows how to configure the TTL to 60 seconds.

networkaddress.cache.ttl=60

 

Option 2:

Dzimitry Kashlach created the “DNS Cache Manager” which is available in JMeter 2.12 and later versions. DNS Cache Manager is bundled with JMeter you don’t have to add any additional jar file for this.

ref: http://jmeter.512774.n5.nabble.com/DNS-Cache-Manager-improvement-for-testing-CDN-td5720797.html

  Steps:

  1. Add “DNS Cache Manager” Thread Group or Test Plan
  2. Check “Clear cache each iteration”
  3. It’s done
See the below table for more information on DNS Cache Manager

Parameters

Attribute Description Required
Name Descriptive name for this element that is shown in the tree. No
Clear cache each Iteration If selected, DNS cache of every Thread is cleared each time new iteration is started. No
Use system DNS resolver System DNS resolver will be used. For correct work edit $JAVA_HOME/jre/lib/security/java.security and add

networkaddress.cache.ttl=0

N/A
Use custom DNS resolver Custom DNS resolver(from dnsjava library) will be used. N/A
Hostname or IP address List of DNS servers to use. If empty, network configuration DNS will be used. No
Add Button Add an entry to the DNS servers table. N/A
Delete Button Delete the currently selected table entry. N/A