Distributed Testing – By JMeter And Docker

Today in digital revolution more and more services are being virtualized, and Docker is an important part of that.

Docker is an open-source platform with the goal of simplifying and optimizing the software life cycle. Docker provides virtualization services that ease the replication of the working environment.

Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on.

Comparing the two stacks, it is clear that the Docker approach to virtualization reduces resource occupation for the CPU, Memory and File System. This saving is obtained because the Docker stack avoids recreating many Guest OS with unnecessary duplications and avoids emulating the complete OS

Docker works in two phases:

1. Composing the environment to be virtualized, described by a minimal set of information (e.g. which linux OS, installed shell, JMeter version, etc). At the end of this step we get the Docker image, which describes the starting point of next step. 

2. Starting from the image, Docker can begin execution by creating a Docker container, which is the virtual environment with the information. Here the business logic processes run and produce results (e.g. a web application will offer its front-end, a JMeter instance can execute a performance test, etc.).

How to Use the Docker Container with JMeter

Docker enables sharing the JMeter tests between users and replicating the test environment. This can be helpful for sharing knowledge between users of different levels, for saving time as not every user needs to set up JMeter tests, and also for ensuring the testing environment doesn’t affect their other work.

Performance test using JMeter not directly installed on the test machine, but rather on a Docker container.

Distributed testing means that a test is split into several parts and each of these parts can be performed over a network on a separate machine (physical or virtual)

With JMeter, distributed testing is based on the client-server model, where two kinds of JMeter instances interact over the network to perform one jmx test script. The first kind of JMeter instance is called the client. The JMeter client instance is the centralized injector of test session. This instance is the main controller that decides which JMX script is executed and when. 

For various reasons (e.g. limitation of local resources, network firewall) the client distributes load generation to other JMeter instances, called servers. The JMeter servers are “distributed” over the network. They receive the JMX script to be executed from the client.

Docker setup for JMeter

Pre Condition#

Ensure that docker is installed in your machine. Once it is installed, the rest is easy. You just need to follow the steps here.

Run below commands one by one.

*********************Pull or Create docker image***************************

1.Create a jmeter Base,slave and master image by below command:

*Change to directory where docker file resides.

*File name should be “Dockerfile”.

*Find the respect docker file at DockerHub and build image as per your settings/Customization.You can find respect docker files from Docker Hub.

docker build -t <Name of Image> .

OR

You Pull all 3 images from below commands from Docker Hub.

docker pull mnazim1541/jmbase

docker pull mnazim1541/jmmaster

docker pull mnazim1541/jmslave

Similarly run other 2 commands to fetch the images from docker hub.after that you will have all 3 images : jmbase ,jmslave and jmmaster.

*******************Create Master & Slaves Containers***************************

2. Create container for master & slaves by running the respective images.

Run below command to create the container for JMeter Master.

docker run -dit –name master mnazim1541/jmmaster /bin/bash

Run below commands to create the containers for JMeter Slaves (Run n number of times below command to generate n slaves)

docker run -dit –name slave01 mnazim1541/jmslave /bin/bash

docker run -dit –name slave02 mnazim1541/jmslave /bin/bash

docker run -dit –name slave03 mnazim1541/jmslave /bin/bash

Note : Docker will automatically pull the docker image I have uploaded and create 3 containers for JMeter server. If you need more containers, keep executing above command just by changing the container name.

********************Fetch the IP address of slaves machines**********************

3.Run the below command to get the list of ip addresses for these containers.(Use GIT Bash to execute below command)

docker inspect –format ‘{{ .Name }} => {{ .NetworkSettings.IPAddress }}’ $(docker ps -a -q)

******************* Go to inside the Master container ***************************

4. Go inside the container with the below command and we can see if the file has been copied successfully.

docker exec -it master /bin/bash

**********************Copy Scripyts & jmeter files to container****************

5. Run below command to copy the script to JMeterFiles folder on container from local host.

docker exec -i master sh -c ‘cat > /JMeterFiles/JmeterDemo_Test_Script.jmx’ < C:/DockerizedJMeter/JMeterFiles/JmeterDemo_Test_Script.jmx Copy

Run below command to copy&Replace the user.properties on the container if wanna change property file.

docker exec -i master sh -c ‘cat > /jmeter/apache-jmeter-3.3/bin/user.properties’ < C:/DockerizedJMeter/user.properties Copy

************** Run the test on Jmeter Master (Non distributed Mode)***************

5.Run the test in master to see if it works fine [not in distributed mode]. Docker container will be able to run the JMeter test as it has all the softwares & dependencies to run the JMeter test.

jmeter -n -t JmeterDemo_Test_Script.jmx -l Result.jtl

*********** Run the test on Jmeter Master (Distributed Mode)******************

6.Run below command to run the test in distributed using docker containers.(IP addresses of all the slaves machine)

jmeter -n -t JmeterDemo_Test_Script.jmx -R 172.17.0.3,172.17.0.4,172.17.0.5 -l Test_Result.jtl

********** Copy the generated result file from container to local system**************

7. Run below command to copy file from container to local host.

docker cp master:/JMeterFiles/Test_Result.jtl .

********************* Generate JMeter Dashboard******************************

8.Run below command to generate the Jmeter dash board .(Note: folder “JMeterHTMLReports” should be empty)

jmeter -g C:\PerformanceTesting\Results\Test_Result.jtl.jtl -o C:\DockerizedJMeter\Results\JMeterReport

JMeter Dashboard Report

References:

https://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html

https://docs.docker.com/get-started/

https://www.blazemeter.com/blog/jmeter-distributed-testing-with-docker

Leave a Reply