JMeter on AWS: Performance Testing on Cloud
JMeter is highly scalable performance testing tool. It can be used to perform distributed tests for large number of users. Since it may not be feasible for many of us to setup required physical infrastructure for distributed testing, we can use cloud services like AWS to perform this task. This post shows how to setup JMeter on AWS to carry out performance testing in cloud environment.
In this tutorial, we will setup JMeter Master-Slave configuration on 3 AWS EC2 instances. As shown in the illustration below, we will have 1 master sending tests to 2 slaves. These slaves in turn will run the tests on application and collect results. After the load test, slaves will send the results to master instance. Master will then combine both the results and generate a report.
Before starting with setup process however, let’s check out some background information. JMeter uses Java RMI (Remote Method Invocation) to perform distributed testing. RMI requires all systems to be in same subnet for communication. Since the AWS EC2 instances may not be in the same subnet, we’ll need to setup SSH tunneling for them to communicate.
We need to have our JMeter script on master system only. No need to copy them on slave systems. Also, load will be generated from both slave systems. Meaning if you want to generate load of 100 users on application, your JMeter script on master should have 50 users specified.
Now that we have all the background details, let’s get into the actual setup process. We have divided the setup procedure in 4 sections as below.
- Configuring EC2 instances
- Setup port forwarding (tunneling)
- Configuring JMeter
- Run JMeter on AWS
Let’s check them out one by one.
Configuring EC2 instances
- Spin up 3 EC2 instances and install an OS on them. We have used RedHat OS here but you can choose other OS as per your requirement.
- Install Java and JMeter on all 3 instances. Below is the command to install JMeter.
1yum install jmeter - Since we are setting up SSH tunnel, it’s a good idea to steer clear of stale connection and keep SSH alive. This can be done by adding/updating below lines in /etc/ssh/ssh_config file.
12ServerAliveInterval 60ServerAliveCountMax 3
Setup port forwarding (tunneling)
- In our case, 3 connections will be required between master and slaves. 2 connections will be from master (RMI and JMeter connection) and 1 connection will be from slaves (RMI).
- To setup tunneling for slave 1 system, use below command on your master system.
123ssh -L 24001:127.0.0.1:24001 \-R 25000:127.0.0.1:25000 \-L 26001:127.0.0.1:26001 -N -f <username>@<slave1IP> - Similarly, use below command on master system to setup tunneling for slave 2.
123ssh -L 24002:127.0.0.1:24002 \-R 25000:127.0.0.1:25000 \-L 26002:127.0.0.1:26002 -N -f <username>@<slave2IP>
Configuring JMeter
- We need to configure JMeter on both slave systems to listen to ports where master will be sending tests. To do this on slave 1 system, add/update below lines in jmeter.properties file located in bin directory.
123server_port=24001server.rmi.localhostname=127.0.0.1server.rmi.localport=26001 - Similarly, update jmeter.properties file on slave 2 system with below lines.
123server_port=24002server.rmi.localhostname=127.0.0.1server.rmi.localport=26002 - Next, update the jmeter.properties file on master system with below lines. This configures master to send tests to slaves and receive results.
123remote_hosts=127.0.0.1:24001,127.0.0.1:24002client.rmi.localport=25000mode=Statistical
Run JMeter on AWS
We are done with all the required configurations. Now we can start executing our JMeter tests in non-GUI mode. But first, we need to start JMeter server on slave systems.
- Use below command on both slave systems to start JMeter RMI server. You’ll need to be in bin directory to execute this command.
1./jmeter-server -Djava.rmi.server.hostname=127.0.0.1 - Start test on master server with below command.
1./jmeter -n -t jmetertesplan.jmx –R 127.0.0.1:24001,127.0.0.1:24002 -l jmeteroutput.csv - Use ./stoptest.sh command to stop the test.
We hope the above setup of JMeter on AWS would be useful to you. We would love to hear your feedback via comments.
Great post and explanation. Just want to share that we did this with RedLine13.com. You can get started for free and it will run inside your AWS environment. We don’t need to run in a single subnet, and can run your test cross-region.
why are we ssh tunneling? Is it only because slave system may not be into same subnet otherwise it is not necessary. Am I right? Please confirm.
Thanks for a great post, is there a way to get away from 127.0.0.1 dependency?
To stop the test and to create the .csv file should I launch the “./stoptest.sh” command ? Using it from the ec2 slave machine the command is not received from master. In fact, from the documentation “The command will only be accepted if the script is run from the same host”.
Should I change the port from the jmeter.properties file?
how can I change the heap memory size in jmeter by using command line. Please any buddy help me in that.
is there a way to run it via the Jmeter Gui in AWS
you can try exporting the display of ec2 instance
A small bugfix probably in a version change
–R 127.0.0.1:24001,127.0.0.1:24002 should be in quotes ie –R “127.0.0.1:24001,127.0.0.1:24002”
Also it’s worth noting your jmeter should be the same version on all masters/slaves
what do you mean with “Username” here: -L 26002:127.0.0.1:26002 -N -f @
username is ec2 username .
Jmeter doesnt accept AWSALB cookies used for sticky sessions in load balancer ELB, and throws exception
2019-06-19 15:10:56,736 ERROR o.a.j.p.h.c.HC4CookieHandler: Unable to add the cookie
org.apache.http.cookie.MalformedCookieException: Invalid ‘expires’ attribute: Wed, 26 Jun 2019 09:40:56 GMT
Any resolution for this?
CookieManager.check.cookies=false
this doesnt work