JMETER — Distributed Load testing with Docker

Photo by National Cancer Institute on Unsplash

Introduction

Environment

Example of Vagrantfile:

Let’s start

Run two JMETER Server

#SERVER01
root@vagrant:/vagrant/scripts# sudo docker run -dit --name server01 spy86/jmeter-server:latest /bin/bash
Unable to find image 'spy86/jmeter-server:latest' locally
latest: Pulling from spy86/jmeter-server
f7ec5a41d630: Pull complete
faf4c47c8c61: Pull complete
636165fc8c70: Pull complete
61c982bd9fd5: Pull complete
fe9c632a6e6b: Pull complete
03234c53afe4: Pull complete
44a960d45d1d: Pull complete
9e17146d29b6: Pull complete
Digest: sha256:0e8e61a8a5b76cc4bc258311e481adcbfda026265b7df272018b8a3999bc45e0
Status: Downloaded newer image for spy86/jmeter-server:latest
153539baff2856e727b9a5d3cae540d5ed92d5645f92e8f1234c3142b5b42be7
root@vagrant:/vagrant/scripts#
#SERVER02
root@vagrant:/vagrant/scripts# sudo docker run -dit --name server02 spy86/jmeter-server:latest /bin/bash
4c7197c8f2c6d0167924f0dfa385cafc6a2c2af82b7883e439809e4ca2990d4a
root@vagrant:/vagrant/scripts#
#CHECK IF SERVERS ARE RUNNING
root@vagrant:/vagrant/scripts# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c7197c8f2c6 spy86/jmeter-server:latest "/bin/sh -c '$JMETER…" 33 seconds ago Up 32 seconds 1099/tcp, 50000/tcp server02
153539baff28 spy86/jmeter-server:latest "/bin/sh -c '$JMETER…" 49 seconds ago Up 49 seconds 1099/tcp, 50000/tcp server01
root@vagrant:/vagrant/scripts#

Run JMETER client

#RUN CLIENT
root@vagrant:/vagrant/scripts# sudo docker run -dit --name client spy86/jmeter-client:latest /bin/bash
Unable to find image 'spy86/jmeter-client:latest' locally
latest: Pulling from spy86/jmeter-client
f7ec5a41d630: Already exists
faf4c47c8c61: Already exists
636165fc8c70: Already exists
61c982bd9fd5: Already exists
fe9c632a6e6b: Already exists
03234c53afe4: Already exists
44a960d45d1d: Already exists
9e17146d29b6: Already exists
Digest: sha256:ff565e74489269d55edfcfa918911757faf9b8913373ee2efbddd918ecc8d80e
Status: Downloaded newer image for spy86/jmeter-client:latest
20c5d883360031471baaf152a867a27a90a814677bb68ef4a804948ddf1f68f8
root@vagrant:/vagrant/scripts#
#CHECK IF CLIENT ARE RUNNING
root@vagrant:/vagrant/scripts# docker ps | grep client
20c5d8833600 spy86/jmeter-client:latest "/bin/bash" 54 seconds ago Up 53 seconds 60000/tcp client
root@vagrant:/vagrant/scripts#

⚠️ If we run it on one virtual machine, we will need to get the IP addresses of the containers. We can do this with the command below:

root@vagrant:/vagrant/scripts# docker inspect --format '{{ .Name }} => {{ .NetworkSettings.IPAddress }}' $(sudo docker ps -a -q)
/client => 172.17.0.4
/server02 => 172.17.0.3
/server01 => 172.17.0.2

Run example test

root@vagrant:/vagrant/scripts# docker exec -it 20c5d8833600 bash
root@20c5d8833600:/# cd sample-test/
root@20c5d8833600:/sample-test# ls -l
total 4
-rwxrwxr-x 1 root root 3694 Apr 25 10:38 sample-test.jmx
root@20c5d8833600:/sample-test#

Let’s run this test first without distributed mode

root@20c5d8833600:/sample-test# jmeter -n -t sample-test.jmx
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/jmeter/apache-jmeter-5.0/lib/log4j-slf4j-impl-2.11.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/jmeter/apache-jmeter-5.0/lib/log4j-slf4j-impl-2.8.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Creating summariser <summary>
Created the tree successfully using sample-test.jmx
Starting the test @ Mon May 24 19:28:27 UTC 2021 (1621884507219)
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary + 7 in 00:00:02 = 2.9/s Avg: 160 Min: 81 Max: 378 Err: 0 (0.00%) Active: 3 Started: 3 Finished: 0
summary + 325 in 00:00:28 = 11.7/s Avg: 120 Min: 78 Max: 506 Err: 0 (0.00%) Active: 0 Started: 5 Finished: 5
summary = 332 in 00:00:30 = 11.0/s Avg: 121 Min: 78 Max: 506 Err: 0 (0.00%)
Tidying up ... @ Mon May 24 19:28:58 UTC 2021 (1621884538076)
... end of run
root@20c5d8833600:/sample-test#

As you can see, the test was run only with the JMETER client. Now try running the same test in distributed mode using docker containers.

root@20c5d8833600:/sample-test# jmeter -n -t sample-test.jmx -R172.17.0.2,172.17.0.3
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/jmeter/apache-jmeter-5.0/lib/log4j-slf4j-impl-2.11.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/jmeter/apache-jmeter-5.0/lib/log4j-slf4j-impl-2.8.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Creating summariser <summary>
Created the tree successfully using sample-test.jmx
Configuring remote engine: 172.17.0.2
Configuring remote engine: 172.17.0.3

Starting remote engines
Starting the test @ Mon May 24 19:29:39 UTC 2021 (1621884579188)
Remote engines have been started
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary + 203 in 00:00:21 = 9.9/s Avg: 181 Min: 81 Max: 364 Err: 0 (0.00%) Active: 10 Started: 10 Finished: 0
summary + 451 in 00:00:10 = 44.6/s Avg: 103 Min: 80 Max: 290 Err: 0 (0.00%) Active: 0 Started: 10 Finished: 10
summary = 654 in 00:00:31 = 21.3/s Avg: 127 Min: 80 Max: 364 Err: 0 (0.00%)
Tidying up remote @ Mon May 24 19:30:12 UTC 2021 (1621884612683)
... end of run
root@20c5d8833600:/sample-test#

Summary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.