Load Testing with Jmeter and Amazon EC2

Alttaf Hussain
4 min readMar 26, 2015
EC2

At Untangl we have just finished moving our corporate product, the Select Benefits platform, from a traditional Data Centre to a Amazon’s AWS. This was a momentous task especially as we approached it with complete automation in mind. Using cloud formation to deploy virtual hardware, Chef to provision and Jenkins to manage everything in one fell swoop. Our product is used by many companies to manage their employee benefits and salary sacrifice plans so it needed to work seamlessly, or there would be trouble!

After our initial stack creation and once we had our basic infrastructure in place we decided to do a load test. We had previously used Neu star and Blazemeter, which are great for one off tests, but will cost you an arm and a leg if you wanted to do it regularly.

Loading your environment

This blog assumes you are running on linux. We used Jmeter to write our tests. In order to create a load test as simply as possible, it is best to use the UI provided by Jmeter. This gives a way to visually create a test and try it before you attempt to scale it.

The first thing that is required is the jmeter-bootstrap package

https://github.com/cfpb/jmeter-bootstrap

git clone

https://github.com/cfpb/jmeter-bootstrap.git

Dependencies

  • Python 2.7 to install JMeter
  • Java 1.5+ to run JMeter

Clone this to a known repository with superuser permissions and ensure you have the correct versions of python and Java installed.

sudo su [not sure if this is right?]

so you are superuser then go into the jmeter-bootstrap folder and run

python bin/JMeterInstaller.py

to install jmeter — then, if everything goes well, you should have jmeter installed. You can fire up jmeter after it has completed by going into the jmeter-bootstrap directory and running:

apache-jmeter-2.[num]/bin/jmeter.sh -t tests/my_test.jmx

(where num is the version of apache jmeter)

[example apache-jmeter-2.12/bin/jmeter.sh -t tests/my_test.jmx]

The Jmeter UI should now be up!

[screen shot of my custom test]

You will have a sample test plan, which you can then begin to tweak — I would advise reading the documentation to familiarise yourself with a test plan.

http://jmeter.apache.org/usermanual/test_plan.html

The main points to consider are:

  1. Thread Group — as the screen above shows the number of concurrent threads to run and the number of times to loop over your test.
  2. Samplers — These are the actual http/ftp etc requests to endpoints of your application.
  3. Listeners — used for interpreting the results.

Follow these instructions to build your first test.

http://jmeter.apache.org/usermanual/build-web-test-plan.html

Once you have written your test plan, which could be as simple as going to the home page of your site, and you have a valid jmx file that you have run from your local machine, you are ready to go to amazon!

Running the test on Amazon Ec2

In the same directory you loaded the jmeter-bootstrap i.e. parent of jmeter-bootstrap create a folder call jmeter-ec2 go into this folder and do a git clone of the jmeter-ec2 repository from github.

https://github.com/oliverlloyd/jmeter-ec2

git clone https://github.com/oliverlloyd/jmeter-ec2.git

Extract the contents of example-project.zip

Dependencies

Prerequisites specific to using Amazon:

  • That you have an Amazon AWS account. See here.
  • You have Amazon’s API tools installed on your machine. See here.

Copy the test plan you created from your jmeter-bootstrap to the jmx folder and call it jmeter-ec2.jmx

cp jmeter-bootstrap/test/testplan.jmx jmeter-ec2/jmx/jmeter-ec2.jmx

(idiot level guide to use jmeter-ec2 can be found here http://www.http503.com/2012/run-jmeter-on-amazon-ec2-cloud/#example)

Once you have the amazon api ec2 tools installed (only ec2 not the whole tool chain) you need to update your .bashrc profile (assuming you are running on linux, windows i have no idea) for the user you will be running the script as — an example is below:

# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
export AWS_ACCESS_KEY=Aasfdsdasdsd
exportAWS_SECRET_KEY=mDasdasdsaDDASsdsdR
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
export EC2_HOME=/usr/local/ec2/ec2-api-tools-1.7.3.0
export PATH=$PATH:$EC2_HOME/bin

Once you have all the pieces in place, you can run your test by logging in as the appropriate user and going to the jmeter-ec2 directory and running:

./jmeter-ec2.sh

you can optionally add more instance by using the “count=3” parameter

You should have a live instance in the cloud running a load test now!!!
The results will go into the jmeter-ec2/results directory. These will be in jtl format and can be opened as csv. The headings are in the following format:

timeStamp elapsed label responseCode responseMessage threadName dataType success bytes grpThreads allThreads Latency Hostname

Enjoy!!

credit due to:
https://github.com/oliverlloyd/jmeter-ec2
https://github.com/cfpb/jmeter-bootstrap

Thanks for reading ☺

--

--

Alttaf Hussain

Keen Technologist in the Digital Identity space. Working for a revolutionary new tech start up YOTI trying to give data back to the users.