Art and Craft of Distributed JMeter


Almost, every enthusiastic tester must have thought about learning performance testing and when they search about tools and techniques to do so, JMeter is the unanimous word they hear.
It’s open source, platform independent and dearly programmable to fit different needs.
To learn basics about how it’s setup and how it works, the primary website(link) is a sufficient read.
But as soon as you get to know about the tool in length and it’s usage, one starts getting stuck and has a list of pros and cons like any other tool.
I mentioned few pros above, now time for some cons namely out of memory exceptions, JMeter able to handle limited threads on a single machine, unease in using complex variables and incomplete documentation.
I will help you resolving almost all the cons through some advanced steps, tips and tricks from my experience.
i. OutOfMemory exception can be simply solved by increasing the HEAP size.
Now where to edit this is the key to solve it gracefully.
/bin folder in your apache jmeter folder has a lot of executables.
Say for windows you have jmeter.bat, jmeter-server.bat, jmeter.exe , similarly for Unix you have jmeter.sh jmeter-server.sh
Now, every blog you will notice will suggest, go edit the Jmeter executable, find the word HEAP and edit the min max values.
This works great if you’re lucky, which I’m sure are not since you came here reading another yet useful article on learning about distributed JMeter setup!
Now, keep a note that the file which you edit, is the same one you run at a later stage, only then you will be able to successfully resolve this error.
E.g: if you edit jmeter file by doing
vim jmeter
Find and edit values for HEAP size, then while running make sure you run
jmeter -n -t script.jmx
And NOT
./jmeter.sh -n -t script.jmx
Both commands work but real benefit will come from former.
PS: You will find the option to edit HEAP size in jmeter file and not in jmeter.sh. Go find out. Why?
I also don’t know the reason for this noble cause of having separate files altogether which do almost the same job they are supposed to.
ii. Limited threads on a single machine: It’s time to scale? Go distributed!
JMeter is both dependent on the node’s hardware configuration and the maximum throughput it can achieve using the same. In order to go beyond that, either one has to upgrade to a better config machine or connect multiple machines and achieve increased throughput.
Former option is valid only in few cases but in order to achieve sustained load/scale, going distributed is the way forward.
So, I will give step by step on how to achieve the same.
Following nomenclature will be used to point to 3 different machines:
i. Master
ii. jmeter1 (Slave 1)
iii. jmeter2 (Slave 2)
STEP I
Access Slave 1 and make the following entry/edits in the jmeter.properties file present in jmeter’s /bin folder
server_port=24001
server.rmi.localhostname=129.x.x.x
where 129.x.x.x, is the public IP of the machine.
Access Slave 2 and make the following entry/edits in the jmeter.properties file present in jmeter’s /bin folder
server_port=24002
server.rmi.localhostname=126.x.x.x
where 126.x.x.x, is the public IP of the machine.
Access Master and the make the following entry/edits in the jmeter.properties file present in jmeter’s /bin folder
 remote_hosts=127.0.0.1:24001,127.0.0.1:24002
 client.rmi.localport=25000
 mode=Statistical
STEP II.
To setup distributed system of JMeter, instead of jmeter.sh, jmeter-server.sh/jmeter-server.bat will be used.
Run the following command of Slave 1 and 2 respectively
./jmeter-server -Djava.rmi.server.hostname=129.x.x.x
./jmeter-server -Djava.rmi.server.hostname=126.x.x.x
This will initiate, two jmeter slaves ready to be connected to master(yet to be connected), more slaves can be started similarly
STEP III.
Once the slaves are ready, master needs to connect to the running slaves by running the following command.
./jmeter -n -t testscript.jmx -R  129.x.x.x:24001,126.x.x.x:24002 -l jmout.csv -Djava.rmi.server.hostname=192.x.x.x
where 192.x.x.x is the IP address of the master machine,
testscript.jmx is the test script that will be run
jmout.csv is the test report file
Note: Master machine doesn’t run the script but passes the same to the slaves. So in above example, you will get twice the throughput and not 3x.
some more details here:
hhttp://www.testingdiaries.com/jmeter-on-aws/