Site icon Vinsguru

JMeter – Distributed Load Testing using Docker in AWS

In the Previous post, We had learnt how to use docker in creating multiple containers running jmeter-server for distributed load testing. But we had created all the containers in the same host. Even if we can not use the single-host containers for performance testing with huge load, before pushing your performance test script related changes to AWS/any other cloud service providers, that setup will be useful to test your scripts in local.

In this post, we will see how to use docker in AWS for JMeter distributed load testing.

Creating AWS Instances:

Creating docker-containers:

As our AWS instances are up and running, Lets create a docker container on each host by issuing below commands.

Now we have docker containers for jmeter-master and jmeter-server are up and running fine with all the dependencies. If we try to find the IP address of these containers, they all might look same – [172.17.0.1] for all the containers. So, our jmeter test will NOT work in this set up as master can not identify the slaves in the network.  If you remember, we ran all our docker-containers on same host. The containers on the same host will be able to talk among themselves with container’s specific IP address as docker-engine creates a default network for these containers on the same host.

But in this AWS, the set up is almost as shown below. The master-container inside the host can NOT talk to the slave-containers on the other hosts – because containers on each host will be in their own separate network. So they can not communicate.

The communication among the docker-containers on different hosts will be routed via their hosts. So, it can be easily fixed by using  port mapping & using host IP instead of containers.

First lets run below command to stop and delete all the containers.

sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)

Port MappingWhile creating a container, we will be mapping the exposed ports of containers to a host port. So, by talking to host on the mapped port, you will be talking to the actual container.

java.rmi.server.hostname Property: As the containers have their own ip addresses, we need to make Jmeter to communicate via host ip by updating java.rmi.server.hostname. For more info on java rmi properties, check here.

Dockerfile for JMeter Client / Master:

It does not require any change.

Dockerfile for JMeter Server / Slave:

It needs to be modified slightly as shown here.  I have added -Djava.rmi.server.hostname=$LOCALIP while starting jmeter-server.sh. LOCALIP will be a variable and the value will be passed at run time while creating the container.

 

Lets create jmeter-server containers on each host [except master] using below command. [Note: I have used different docker image – vinsdocker/jmawsserver]

sudo docker run -dit -e LOCALIP='52.10.0.2' -p 1099:1099 -p 50000:50000 vinsdocker/jmawsserver /bin/bash
sudo docker run -dit -e LOCALIP='52.10.0.3' -p 1099:1099 -p 50000:50000 vinsdocker/jmawsserver /bin/bash
sudo docker run -dit -e LOCALIP='52.10.0.4' -p 1099:1099 -p 50000:50000 vinsdocker/jmawsserver /bin/bash

Run the below command on master host to create a jmeter master container.

sudo docker run -dit --name master -p 60000:60000 vinsdocker/jmmaster /bin/bash

After creating all the containers, the setup is almost as shown below.

 

We can run the test now in the master container by issuing below command.

./jmeter -n -t docker-test.jmx -Djava.rmi.server.hostname=52.10.0.1 -Dclient.rmi.localport=60000 -R52.10.0.2,52.10.0.3

 

Summary:

By using docker, we do not need to worry if we have same version of jmeter and java are installed on each host. docker take cares of all these.  Using docker-containers on a single host was very simple and straight forward. But when you use it in AWS, in order to make the containers talk among themselves, we need to use java.rmi.server.hostname property and port mapping. Once we do these, then everything works as expected.

Instead of using LOCALIP variable while creating a docker jmeter-server container, we can also use below techniques to communicate with slaves.

We will see how to use above techniques in the next post.

 

Happy Testing 🙂

 

Share This:

Exit mobile version