Developers Blog @ Espris

Saturday, April 30, 2011

How to use jMeter in server mode over an SSH tunnel - Part 2 - Mutliple server instances

This article describes how to run one client JMeter instance with MULTIPLE server instances with inter-JMeter communication tunneled over SSH.

Please read the previous part first (How to use jMeter in server mode over an SSH tunnel).

1) SSH TUNNELS (created from the client machine)
We assume that:
- we have a client machine and a server machine
- client JMeter instance runs on the client machine
- both server JMeter instances run on the server machine.
- we have two server JMeter instances

Create following tunnels:
(tunnels to instance 1)
Local port: 55501 -> 127.0.0.1:55501
Local port: 55511 -> 127.0.0.1:55511
(tunnels to instance 2)
Local port: 55502 -> 127.0.0.1:55502
Local port: 55513 -> 127.0.0.1:55513
(mutual tunnel for callback)
Remote port: 55512 -> 127.0.0.1:55512

2) CLIENT CONFIG
remote_hosts=127.0.0.1:55501,127.0.0.1:55502
client.rmi.callbackport=55512

3) PREPARE JMETER SERVER INSTANCES
Create 2 separate JMeter application folders on the server machine, e.g.
jakarta-jmeter-2.3.4-inst1
jakarta-jmeter-2.3.4-inst2
and put the patched JMeter application into each of them.

They will have different configurations in jmeter.properties. (The same result could be also achieved by having only one application instance and by specifying the different configuration parameters in the start up script on command line.)

Prepare start-up scripts:
(start-jmeter-server-inst1.sh)
#!/bin/sh
./jakarta-jmeter-2.3.4-inst1/bin/jmeter-server -Djava.rmi.server.hostname=127.0.0.1 2>&1 >inst1.log &

(start-jmeter-server-inst2.sh)
#!/bin/sh
./jakarta-jmeter-2.3.4-inst2/bin/jmeter-server -Djava.rmi.server.hostname=127.0.0.1 2>&1 >inst2.log &

3) SERVER CONFIG - INSTANCE 1
(jakarta-jmeter-2.3.4-inst1/bin/jmeter.properties)
server_port=55501
server.rmi.localport=55511
server.rmi.localhostname=127.0.0.1

4) SERVER CONFIG - INSTANCE 2
(jakarta-jmeter-2.3.4-inst2/bin/jmeter.properties)
server_port=55502
server.rmi.localport=55513
server.rmi.localhostname=127.0.0.1

5) GO
Open SSH connection from client to server machine
Start client JMeter
Start server JMeters
Remotely run your test
Check inst1.log and inst2.log for logs from the server instances

6) Done!


TROUBLESHOOTING
1) Ports are already in use on server machine
Make sure no previously started JMeter is running in the background.

2) There are no results coming back to client instance
Make sure you patched also the client instance JMeter application.

Saturday, October 17, 2009

How to use jMeter in server mode over an SSH tunnel

INTRODUCTION

Apache JMeter is open source software, a 100% pure Java desktop application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions. (http://jakarta.apache.org/jmeter/)

jMeter can be run in "GUI", "non-GUI" and "server" modes. You can control and monitor multiple instances of  jMeter running in server mode with a single instance that is running in GUI mode. You may want to do this over a secure SSH connection when connecting to remote servers.

(This how-to covers tunneling of the jMeter instance-to-instance communication, not the jMeter-to-the-tested-application communication.)

THE SOLUTION

jMeter uses RMI with callbacks for inter-instance communication. We will configure jMeter and the SSH tunneling based on the great article "SSH Tunneling for Java RMI, Part-II" by Pankaj Kumar.

We will need to:
1. Force jMeter on server side (server mode) and client side (GUI mode) to bind to localhost
2. Set the RMI registry port and the method  invocation port of jMeter server to an arbitrary value
3. Force jMeter client to listen for RMI callbacks on an arbitraty port
4. Tunnel the RMI ports

To achieve points 1 and 3 we will need to patch jMeter source code and build it. The patch applies only to jMeter version 2.3.4.

I will suggest my jMeter code changes to be incorporated into the jMeter project. This may take some time and the changes may be even refused, so in between the patch is probably the only way how to tunnel over SSH. It is possible that if the code will be accepted by jMeter project, it will be somehow modified and the configuration for the next versions will be different.

WHAT THE PATCH DOES

- Adds jMeter parameter server.rmi.localhostname - jMeter by default 1) binds to the host's hostname and 2) refuses to bind to localhost. If this parameter is set, jMeter will bind to the specified ip/hostname and (only if this parameter is set) won't complain even if it is localhost.

- Adds jMeter parameter client.rmi.callbackport - jMeter will listed on this port for RMI callbacks.

PREREQUISITIES

JDK
Ant
SSH client, e.g. Putty (http://www.chiark.greenend.org.uk/~sgtatham/putty/)

HOW TO

Let's assume that:
- server RMI registry port is 55501
- server RMI method invocation port is 55511
- client RMI callback port is 55512

1. Download both the jMeter 2.3.4 binaries and source code (http://jakarta.apache.org/jmeter/) and extract them into the same directory of your choice

2. Download my patch and copy it over the original jMeter source code.

3. Build jMeter (http://wiki.apache.org/jakarta-jmeter/BuildingJMeter)

4. Copy it to both the server and client machine

5. Edit the server jmeter.properties:
server_port=55501
server.rmi.localhostname=127.0.0.1
server.rmi.localport=55511

6. Edit the client jmeter.properties:
remote_hosts=127.0.0.1:55501
client.rmi.callbackport=55512

You will also want to switch to batch mode to lower the network traffic:
mode=Batch
num_sample_threshold=250

7. Configure the tunnelling
Local port: 55501 -> 127.0.0.1:55501
Local port: 55511 -> 127.0.0.1:55511
Remote port: 55512 -> 127.0.0.1:55512

8. Start the jMeter server and client using (to associate remote stubs with localhost):
server (example for linux): ./jakarta-jmeter-2.3.4/bin/jmeter-server -Djava.rmi.server.hostname=127.0.0.1 &
client (example for win): jakarta-jmeter-2.3.4\bin\jmeter.bat -Djava.rmi.server.hostname=127.0.0.1

Done!

Next part: How to use jMeter in server mode over an SSH tunnel - Part 2 - Mutliple server instances