How to Configure JMeter in Eclipse

Complete end to end configuration of JMeter in Eclipse

Here we will learn how to Configure JMeter in Eclipse. If you are planning to do some customization in JMeter, then, you must be thinking of using some IDE like Eclipse because a lot can be done using an IDE.

There are a lot of blogs and tutorials on this topic, but share partial information regarding End to End configuration.

http://jmeter.apache.org/building.html

http://gerardnico.com/wiki/jmeter/eclipse

http://artur.ejsmont.org/blog/content/how-to-build-jmeter-from-sources-in-eclipse

 

This is a long post with series of configuration, but resolves all the problem you may face with Eclipse and JMeter Integration, for ease of reading it is divided into three parts:

  1. Import JMeter Source into Eclipse
  2. Run JMeter using ANT target
  3. Settings to Properly Configure JMeter in Eclipse

 

1. Import JMeter Source into Eclipse

For that, you will have to first configure JMeter source in some IDE like eclipse.

  • First, create a Java project

Create Java Project

Create Java Project Finish

  • Import JMeter source into the recently created Java project

 Import JMeter Source

 

Import JMeter Source 2

Now, we have successfully imported the JMeter source in Eclipse. Now, let’s launch the JMeter.

 

2. Run JMeter using ANT target

There are two ways to launch JMeter:

  • Standard method – Using Command line, the most common way to launch JMeter
  • Using ANT Target – JMeter contains ANT target to launch JMeter

We have an ANT target in JMeter that makes this task really easy. So, we will use the second method (Using ANT Target) to launch JMeter

NOTE: You just need the ANT plugin installed in eclipse to take advantage of ANT. You need to have Ant (Version 1.9.6) in your IDE

To use targets define build.xml, let’s first add the build.xml files to Ant window in Eclipse.

There are two build.xml files, one is in “root” folder and another is in “extras” folder. Add both these build.xml files.

Add Build.xml

Now, use the ANT Target (run) defined in build.xml file kept in “extras” folder

As soon as you execute the “run” target you will see errors in the src folder and JMeter will not launch.

12959509_1052926691415109_1426361295_o

Now, to resolve these issues we have to do some more configuration. Let’s move to the 3rd part of the post

 

3. Setting to Properly Configure JMeter in Eclipse

You will face few challenges in the smooth running of JMeter project in Eclipse. We will now see the solutions to these challenges.

Challenge 1:

Eclipse creates some files and folders when you create a Java Project in Eclipse that includes a bin folder. JMeter already has a bin folder that contains important property files and executable to run the JMeter jar file. Eclipse will use same JMeter “bin” folder as output folder (to keep .class files when we build the Java project) because of which Eclipse deletes all the content that is already present in the folder.

Because of this clash, eclipse deletes all the files from this “bin” folder when we build the JMeter project using eclipse.

JMeter Bin Folder Compare

Solution: Change the eclipse output folder

Java Build Path

Change Eclipse Default Bin Folder

Now, copy the missing files from the unzipped JMeter source project to the “bin” folder of eclipse JMeter project, manually.

Bin and Eclipse Bin Folder

Challenge 2: Errors in the Project

You will see errors in the project because of missing JMeter jar files.

Configure JMeter in Eclipse - Errors

Solution:

To resolve these errors we have to do following 3 steps

1. Download the required “jar” files

2. Configure the Build Path

3. Add Source folders to the build path

Download the required “jar” files

JMeter source does not contain the jar files as a bundle. But that doesn’t mean you have to download it manually or copy paste from the JMeter binary distribution. You can download it in just one click using ANT target.

JMeter uses ANT as a build tool that has different ANT targets for different actions necessary for project building. For example, downloading of all the required jar files.

Now, download the required jar files. There is a download_jar target in build.xml kept in the root folder that downloads all the missing jar files. 

Build.xml download jar files

Configure Build Path

Now, after downloading the jars, you can use source JMeter like you use binary JMeter, but we still see errors in Eclipse even though the jar files are present in the “ext” and “lib” folders now. But these errors are because eclipse doesn’t know from where these jar files need to be picked. That is why eclipse displays these errors.

Now, to fix this we simply have to add all the jar files present in “lib” and “ext” folder into classpath using “Configure Build Path”

JMeter - Configure Buildpath

Once done, we will start seeing intelligence help one’s eclipse know from where these jar files are to be picked.

You may still see few files showing “cross/error” symbol. If you check the error by opening one of those java files you will observe.

Add Source folders to the build path

You will still observe these errors in the Java file related to the wrong package. To resolve this we have to add folders to the build path.

Change in eclipse .property file

Add all these folders to the Java Build Path to resolve the errors.

Configure JMeter in Eclipse - Add Source Folders1

 

I hope this article was helpful to resolve all the issues you faced with Eclipse and JMeter integration.

Congrats!!… If you have reached the end of this article and JMeter to work smoothly with an IDE without any errors.

If you still facing any issue just write a comment below. I will try my best to help you out.

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

Badboy Script Gets Logout in JMeter

Badboy script gets logout in Jmeter just after doing a login transaction?

Did you ever face this issues while running the script in JMeter which was recorded using Badboy tool? If yes, the solution is really simple.
Just open the “HHTP Request” sampler and check the “Follow Redirect” checkbox.

When I first encountered this problem I thought this is some kind of weird issue with JMeter, but made sense when I got to know the reason behind it.

Reason:
Badboy is a great tool when it comes to recording a flow. But the script that it creates is not exactly same as JMeter creates.

I had used Badboy tool to record the scenario/workflow because of some ajax requests were not getting captured by the JMeter while recording. After recording the workflow in the Badboy tool, I had exported the script as a JMeter file using the Badboy tool itself.

The issue occurred when the script executed in JMeter tool and the issue was when I execute the script it gets logout or redirects to the logout page, each time. To me, that was a weird situation as all the dynamic values were properly correlated.

While doing Google, I came across to this Forum that finally give the answer that solves this.

When you record the script in Badboy and exported to JMeter, by default, the sampler has “redirect automatically” checked by switching that to “follow redirects” the problem will get resolved.

If “Redirect automatically” checkbox is checked then, it sets the underlying HTTP protocol handler to automatically follow redirects.

 

JMeter - Follow Redirect