Dockerized JMeter
In this article I will describe how create an docker cluster for JMeter load/performance test.
What is JMeter?
If you don’t know what JMeter is, this is the first question you should do. According with his own descriptions JMeter is:
The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.
JMeter is a little old application for testing applications. There is new solutions with more interesting outputs, but you will not find so much functionalities there than you can find using JMeter. Gatling is good, but it is difficult to find good examples and tutorials
You can use JMeter to stress your application discovering which point of your application cannot scale.
In this very small tutorial, I will not focus on how create a JMeter test plan. The test plan that I will use only request a HTTP GET on github.com. And I will build a Master-Slave solution. The master will knows the test plan, and will send the execution plan to all the slaves. All slaves will execute the same test plan.
What is Docker?
Docker is a platform for creating custom virtualized environments. Instead of creating many machines, you can create a docker image and scale that docker image. With a single text file and a command, you can have your machine as you designed it in any place you want.
Docker is different from a virtual machine because dockers containers shares pieces of the Guest OS, so it is lighter than a Virtual Machine.
Requirements
To run this tutorial you will need:
- Docker installed
- Docker compose installed
Docker is easy to install in Linux. It is a little more complicated in MacOS. If you are using Windows, sorry…
Let’s start…
All code bellow you can find in this repository.
Creating a JMeter docker images
First we need to create two dockers images, the jmeter-master and jmeter-slave. We will use the jmeter-master to scale our test plan. If we have just one HTTP request in our test plan, using the master-slave architecture with n slaves we will get n HTTP request at the same time.
The Dockerfile bellow is my base JMeter image.
To use this image, create a folder named jmeter-base and save this Dockerfile inside, the execute: docker build -t jmeter-base ./jmeter-base
. You will not execute this image, there is no CMD
or ENTRYOPOINT
in the image.
Now we should create more two folders jmeter-master and jmeter-slave.
Now let’s create a docker-compose file to describe our environment.
OK, we have our environment describe in files. How we start it?
The script bellow (re)creates the jmeter-base image, start our environment, and scale the slaves machines.
Starting the test…
Now we should inform the jmeter-master that he can control a lot of slaves machines.
The script bellow, we find all docker slaves IPs (line 1). Then for each *.jmx
file inside a scripts
directory we execute it using all jmeter-slave machines.
The main line at this script is the line 8. In this line we execute jmeter informing all slaves IPs: ./jmeter -n -t <test plan .jmx file> -R<list of slave IPs>
All the results are copied from the containers to the local machine.
Clean up…
To remove all machines, you can use docker-compose:
Possible Improvements
- Create a job (cron, jenkins, etc…) that executes the load testing .
- Create test plans for each service of your system.
- Use CLIChart to create graphs and build a report.
- Create a better test plan to stress the system and get the response time for each situation.
- Use the response time to know how your system scales.
- Create a Docker swarm using the AWS infrastructure or Google Cloud.