First Steps in JMeter

Introduction

In this post we are going to go through the main JMeter features, but first of all, what is JMeter? basically, it is a tool to perform load testing against:

However, we will only cover the HTTP functionalities of JMeter.

Performance tests are required to make sure your application will not crash under heavy traffic, and survive dates such as Black Friday or Christmas. Therefore, it is a very important phase of the web development process.

JMeter is an open source and Java based that provides an GUI to create your test plans, and simulates browser behavior by sending customized request to your website.

JMeter

Installation and Execution

Ubuntu 18

  1. Download binaries from Apache JMeter.
  2. Unzip file:

     tar -xf apache-jmeter-5.0.tgz
    
  3. Run executable file:

     cd apache-jmeter-5.0/bin
     ./jmeter
    

MAC OS

  1. Install it with brew

     brew install jmeter
    
  2. jmeter should be on your PATH

     jmeter
    

Elements of a Test Plan

This parent object will contain all the necessary components to build your test plan.

Thread Group

Thread Group is the first element of your test plan and all samples, controllers and listeners are meant to be under this object. However, listeners are allowed to be under the Test Plan object, and in this case they are applied to all Thread Groups. What can you do from a Thread Group?

Controllers

Sampler

This type of controller let you send different types of requests (e.g. HTTP, FTP, JDBC…).

The HTTP Request controller is used to send requests to the web server.

If you are planning to send multiple request to the same server it is recommended to use Config Element components for your Thread Group, so you can set default request values:

Another interesting option to generate test samplers automatically is HTTP(S) Test Script Recorder.

Logic Controller

We can use these controller to specified how and when to run the samplers. The most relevant types are:

Listeners

Listeners are essential to retrieve the results from your tests and analyze the Sampler requests and responses by looking at tables, graphs, trees, statistics… Moreover, they allow you to save the results in csv or xml files, so you can have a look at them later.

Some of the most relevant listeners are:

JMeter - Results Tree
JMeter - Results Tree
JMeter - Aggregate Report
JMeter - Aggregate Report
JMeter - View Results
JMeter - View Results
JMeter - Data Writer
JMeter - Data Writer
JMeter - Listener
JMeter - Listener
Graphite Dashboard
Graphite Dashboard

In order to save these reports into CSV files you only need give a path a filename. For XML output Save as XML option needs to be selected in Configure.

Timers

Timers add delays to every requests of your Thread Group to avoid overwhelming the server. If you want to apply a timer to only one element, add the timer as a child of it. Some of the common timers are:

Assertions

Assertions are very useful to make sure for instance you are getting the expected response.

The most relevant assertion for HTTP requests is Response Assertion. This assertion allows you to set patterns for Request and Response Headers, Request Data or Response Message.

JMeter - Response Assertion
JMeter - Response Assertion

Templates

JMeter includes some templates to get started. Building an Advanced Web Test Plan is one of them and includes many of the elements described before (config elements, controllers, assertions, listeners, timers…).

JMeter - Left Pane
JMeter - Left Pane

Running Test Plan

There are two options to run your test plan. You can use the GUI provided by JMeter, however this alternative is not recommended, since JMeter consumes much computer memory, and it should only be used for creating the test script. On the other hand, non GUI is much more lightweight and should be used for running the test plan.

jmeter -n -t test_plan.jmx -l results.csv -j jmeter_logs.log

where -n is non-gui mode, -t is Test Plan file, -l file to save results (csv, jtl) and -j JMeter log file.

Conclusion

JMeter is a powerful and customizable tool for load testing, and provides a friendly user interface to create your scripts. However, it is a heavyweight tool compare to other load testing utilities like Gatling or Locust.