An introduction to Apache JMeter

Ramūnas Monkevičius
8 min readDec 2, 2014

--

JMeter is a very nice tool for load testing applications and measuring their performance, but it suffers from a pretty steep learning curve. I am writing this guide to help people learn how to use this amazing tool.

I was lucky enough to be shown the basics of JMeter at a workshop by Goranka Bjedov who is a Capacity Engineer at Facebook. She has years of experience using JMeter and was kind enough to share it with us at the wonderful Belgium Testing Days conference. So after some time of using this amazing tool I thought I should give back to the community and write up a short visual guide for people who want to learn how to use it.

JMeter is written in 100% JAVA, this means that it runs on pretty much every platform imaginable. Also it has only one requirement, JAVA 6 or later JRE has to be installed on your system. If you have that, you are ready to go.

JMeter does not have an installation process, you just download the archive from the official site, extract it and run the application.
The file you want to run is located in the “bin” sub-directory of the newly extracted folder and is named: “jmeter.bat” for Windows and “jmeter” for Linux / OS X systems.
On Windows you simply double click the file, on Linux and OS X you should open up Terminal, navigate to the bin sub-directory in JMeter folder and execute the following command:
./jmeter

If you get the following message: “-bash: ./jmeter: Permission denied” you need to run: “chmod +x jmeter” and try again.

Here is how it looks when you first launch it on OS X

A Screenshot of JMeter on OS X Yosemite

In JMeter you work on Test plans which contain all of the requests that are going to be sent to server and everything else that is related to you test.
You can save/load/edit them.

Most likely when you first use JMeter you will have no idea of how to set up a test plan, so you can use one of the helpfully predefined templates. You can open up the templates screen by clicking on this button in the toolbar.

A screenshot of JMeter with the template button highlighted

For your first test you might want to choose “Building a Web Test Plan” option.

Template chooser window in JMeter

Click the “Create” button.

Sidebar after loading a template with predefined settings

Now you should see that the Test plan on the left hand side of the sidebar was renamed and now has a “Thread Group” called “JMeter Users” with some items in it.

Threads are basically users, so thread group is a group of virtual users.
Below you see “HTTP Request Defaults” which is the part where you define your test target and some other parameters. Below that you can see two HTTP requests called “Home Page” and “Changes”.

Go ahead and click on the “JMeter Users” thread group in the sidebar.
You should see something like this:

JMeter thread group settings screen

Highlighted are the most important settings of the thread group. First of all is “Number of Threads (users)” setting. This one is pretty much self-explanatory. You just input the number of users you want to test with. Lets say we want to simulate the load of 5 users on our website.

The next setting is “Ramp-up Period (in seconds)” which tells how fast to spin up new users up to the number you specified in the previous setting. In this case if this setting is set to five, this means that a new thread is launched every second (number of threads 5 / ramp-up period 5 = 1 second) up until it reaches the total number of threads defined.

Another very important setting is “Loop count”. It defines how many times the test should be run. For reliable results you might want to run your test more than once. There is also an option called “Forever” which will make the test to run continuously until you click the “Stop” button or quit the application.

Next you should check the settings of the “HTTP Request Defaults”. This is where you define which website you are going to test.

HTTP Request Defaults screen in JMeter

Highlighted are the two most important settings on this screen.
First one is the “Server Name or IP”. This is where you input your website domain or IP address.

The second one is the “Protocol”. If your site is served over http there is no need to change anything here, but if it’s server over https you need to input “https” in this field.

You can go ahead and remove the “Changes” http request by right clicking on it and clicking “Remove”, same goes for “Graph results” and “Login”. We won’t be needing them right now.

Now click on the HTTP Request called “Home Page”.

HTTP request configuration in JMeter

This is where you configure the details related to this particular HTTP request.

The Method setting might be useful for those who want to test POST based forms and etc.

The “Path” setting defines the path of the page. For example if you defined your website URL to be “mywebsite.com” in “HTTP Request Defaults” page and set the “Path” setting to “/index.html” JMeter would visit the following URL “http://mywebsite.com/index.html”.

Now all we need is a way to see the results of the HTTP requests. In order to get that we need to right click on the “JMeter Users” thread group, select “Add”, “Listener”, “View Results Tree”.

How to add “View Results Tree” listener to the thread group

Before we run the test there are a few more things to know.
You need to save the test before you run it. You can do it by clicking on the File menu and choosing “Save Test Plan as”.

How to save JMeter test plan

Once that is done, the next thing you need to learn is how to Start/Stop the test and how to see the current status of the test.

JMeter user interface

The start and stop buttons is clearly visible, but the status information is not so obvious.
The grey square at the side of the screen shows the current test status, once the test is running it turns green. On the left hand side of the square you see two numbers. This is the active thread count and the total number of threads to be launched.

When you first run your test I suggest you do it from the “View Results Tree” screen. That way you can check what kind of responses your test is getting from the server and you can quickly notice problems.

Once the test starts running you should see HTTP requests appear here. If all goes well you should see a green check icon next to each request.
When the test is done you should see something like this:

View Results tree listener in JMeter

At first look this doesn’t look very comprehensible. But it gets betten when you switch to the “Parsed” view tab at the bottom of the screen.
Here you can see the request parameters, the actual HTTP request which was sent to the server as well as the RAW response data.

Pro-tip: you can use the select box above the request sidebar in the “View Results Tree” screen to switch to another view.
“HTML (download resources)” for example.
When you use this mode the response data will get rendered.
Keep in mind that JMeter is not a web browser, so the results will look nothing like the actual page, but you will still be able to get the idea of what kind of response data did you get back at a quick glance.

JMeter rendering google.lt homepage

Now all you need is a way to gather some metrics and you are good to go!

To gather metrics I suggest you use the “Summary Report” listener. You can add it to you thread group the same way you did add “View Results Tree” listener.

Why “Summary Report”? It might not have all the bells and whistles like some other data-graphing listeners, but it has one huge benefit. It doesn’t really add any additional overhead to your system. This is important when you are running tests that last multiple hours or you have a machine with limited memory. Some other listeners constantly gather data and occupy more and more memory until there is none left. This can cause problems and impact your test results.

In the “Summary Report” you can clearly see the Average response time, the Min and Max times as well as standard deviation.

To log results to a file simply type in a filename in the field.

JMeter will create a CSV file in the same folder as the application itself. You can use the configure button to set what exactly gets written to the file.

Now once you have a CSV file with all the data you need, you can import it into some plot drawing application and create a pretty graph and do your conclusions. To make your graphs you can use anything you like from Excel to R.

I hope this guide will help people create their first performance test with JMeter and inspire them to dig deeper into this great tool as well as performance testing field.

If you have any questions or just want to chat feel free to contact me at ramunas@kommon3.com or @ramunas_m on Twitter.

--

--

Ramūnas Monkevičius

Engineer, motorcycle fan, traveler, photographer and a whole lot more