Distributed Testing with JMeter on EC2

Here’s a little quickie. I wanted to do some distributed testing with JMeter utilizing EC2 instances as slaves, while running the master/UI locally on my laptop. There are several challenges around this all due to the fact that JMeter chose to use Java RMI as the communications protocol. If you thought the FTP protocol was bad Java RMI is worse. I’ll spare you the gory details and get to what worked for me.

EC2 Instances and Security Group

Ok so first, off you’ll need to spin up one or more EC2 instances, I just chose the Amazon Linux distro.

The key here is the Security Group settings, I simply greated four rules,

Type Protocol Ports Source
Custom TCP Rule TCP 1099
Custom TCP Rule TCP 2048
Custom UDP Rule UDP 1099
Custom UDP Rule UDP 2048

There are only two ports involved here, 1099 is the Java RMI Registry port, and 2048 will be the service port that the JMeter server binds to.

Starting the JMeter Slaves

Install JMeter on the EC2 instances somewhere. When you start it up, use the following:

jmeter-server -Dserver.rmi.localport=2048 -Djava.rmi.server.hostname=`curl -s`

This is doing a couple of things, we’re telling the server to tell Java RMI to make our server bind to a well known port (port 2048), ahh, that’s much better for firewalls. And we’re also telling RMI to forge the server name to be the EC2 Public IP address.

SSH Tunnel to the Slaves

Probably should have mentioned it earlier, but now you’ll need to set up some port forwarding-fu between you and the slaves. This ‘ll work. I’ll tell ya why later.

ssh -R11099:localhost:11099 ......

Starting the JMeter Master/UI

The last bit of trickery is in starting the JMeter client. Here’s what I did

bin/jmeter -Dclient.rmi.localport=11099 -Djava.rmi.server.hostname=localhost -Jremote_hosts=ec2-ip-address,ec2-ip-address

What we’re doing here is a few things, telling the “client” (aka Master (aka UI)) to start its own RMI registry on port 11099, and fooling the registry into believing our local hostname is ‘localhost’.

When the client connects to a slave, it will now say, “hey talk to my RMI server on localhost:11099”. It’ll try to do that on the EC2 instance, and when it does the SSH Tunnel will forward the traffic back to the local machine, and everything will be happy.

Finally the last part of the line, enter the Public IPs of all the EC2 slaves you got.

Good Luck

And that is all I did to get it working for me, hope this helps you too.

2 thoughts on “Distributed Testing with JMeter on EC2

  1. I want to run jmeter slaves in different regions hence different subnets. When i run the jmeter server it binds only to private ip. How do i bind it to the public IP on EC2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s