Tutorial-9122023

Setting up a JMeter Cluster for web server load testing

jmeter cluster design

Setting up a JMeter Cluster for web server load testing

This tutorial shows you how to set up a JMeter cluster for load tests. Like anyone who doesn’t know it yet, the Apache JMeter application is open source software, a 100% pure Java application designed to test functional behavior and measure performance. It was originally developed for testing web applications but has since expanded to other test functions. It can be used to simulate a heavy load on a server, group of servers, network, or object, to test its strength, or to analyze overall performance under different load types.

But as each business approach becomes larger and larger, engineers and testers need to perform more testing to ensure that each expansion module can serve larger consumers without compromising daily production operations. To ensure this, JMeter has introduced its own services by being able to test the performance test under larger environments by performing it as a clustering process.

In the event that your JMeter client computer is unable to simulate enough users to load your server, or is limited at the network level, you can control multiple remote JMeter engines from a single JMeter client. By running JMeter remotely, you can replicate a test on many low-end computers and simulate a larger load on the server. An instance of the JMeter client can control any number of remote JMeter instances and collect all data from them.

Distributed testing is a type of testing in which multiple systems are used to perform stress tests. Distributed testing is used to test Web sites and server applications when they work with multiple clients simultaneously.

1. How does it work

If we are running our load tests locally with single JMeter application, there are certain limitations to the number of users you can run, even if your computer has enough CPU and memory. Due to that, how can we create a scenario with more than 1000 concurrent users using JMeter? Due to this scenario, the idea of JMeter in distributed mode comes in picture.

When we talk about distributing JMeter, we refer to a Master-Slave architecture where JMeter uses Java RMI [Remote Method Invocation] to interact with objects in a distributed network. Below pictures are to summarize the workflow:

svg%3E

By using JMeter under cluster design, you can ensure your testing enable for having a local JMeter (master) that handles the test execution, together with multiple remote JMeter instances (slaves) that will send the request to your target server.

Connection to JMeter cluster / JMeter service can be made via:

  1. JMeter desktop application
  2. SSH / terminal
  3. VNC
  4. API service endpoint (WIP)

svg%3E

2. Installation Phase

For the installation phase, first we’ll list out the inventory of what each server will be. Below are the details:

System Inventory
IP Hostname OS Function Status
172.20.0.111 jmeter01 CentOS 7 x64 bit JMeter server 01 (master/slave) Ready
172.20.0.112 jmeter02 CentOS 7 x64 bit JMeter server 02 (slave) Ready
172.20.0.113 jmeter03 CentOS 7 x64 bit JMeter server 03 (slave) Ready
172.20.0.114 jmeter04 CentOS 7 x64 bit JMeter server 04 (slave) Ready

Now let’s get our hands dirty, we will start by setting up the server with prerequisites, assuming each server are under minimal server configuration. Below are the steps:
[root@jmeter01 /]# yum install -y wget initscripts net-tools

Doing above is optional, just to ensure our installation and review work smoothly. Once installation done, you’ll have the screenshot like below

svg%3E

svg%3E

Next, we need to install Java packages as it’s compulsory for setting up JMeter as a service. Below are the steps:
[root@jmeter01 /]# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm"
[root@jmeter01 /]# yum localinstall -y jdk-8u131-linux-x64.rpm

Process will be like below:

svg%3E

svg%3E

Next, we will install the JMeter packages. In this tutorial, I will use the current stable version for JMeter installation. The steps are like below:
[root@jmeter01 /]# wget https://www-eu.apache.org/dist//jmeter/binaries/apache-jmeter-5.1.1.tgz
[root@jmeter01 /]# tar -zxf apache-jmeter-5.1.1.tgz
[root@jmeter01 /]# ln -s /apache-jmeter-5.1.1 $HOME/jmeter
[root@jmeter01 /]# echo "export JMETER_HOME=$HOME/jmeter" >> /root/.bashrc
[root@jmeter01 /]# echo "export PATH=$PATH:$JMETER_HOME/bin" >> /root/.bashrc
[root@jmeter01 /]# source /root/.bashrc
[root@jmeter01 /]# curl -L https://jmeter-plugins.org/get/ > $HOME/jmeter/lib/ext/plugins-manager.jar
[root@jmeter01 /]# curl -L https://repo1.maven.org/maven2/kg/apc/cmdrunner/2.2/cmdrunner-2.2.jar > $HOME/jmeter/lib/cmdrunner-2.2.jar

Once everything’s done, you will see the progress like shown below

svg%3E

Next, we will use a plugin manager to help to install several java packages needed for our JMeter to run smoothly. Below are the steps:
[root@jmeter01 /]# java -cp $HOME/jmeter/lib/ext/plugins-manager.jar org.jmeterplugins.repository.PluginManagerCMDInstaller
[root@jmeter01 /]# /root/jmeter/bin/PluginsManagerCMD.sh install jpgc-autostop,jpgc-casutg,jpgc-csl,jpgc-dummy,jpgc-ffw,jpgc-filterresults,jpgc-functions,jpgc-json,jpgc-mergeresults,jpgc-prmctl,jpgc-sense,jpgc-tst,jpgc-wsc

If the progress run smoothly, you’ll get as per screenshot below

svg%3E

svg%3E

Now as everything is done on installation part, you will need to create the keystore prior to starting JMeter as slaves. To do this, we can use script that bundle with Apache JMeter packages called create-rmi-keystore.sh . Below are the steps :-
[root@jmeter01 ~]# $HOME/jmeter/bin/create-rmi-keystore.sh

Below are the screenshot

svg%3E

Now pretty much we’ve done for JMeter installation, we can proceed to make configuration in JMeter service for distribution process. You can continue setup the rest of JMeter server as same installation you’ve made for this server.

3. Configuration Phase

Now as for the configuration to make as distributed JMeter, we just need to edit the jmeter.properties inside JMeter /bin folder as per below
[root@jmeter01 ~]# vim /root/jmeter/bin/jmeter.properties remote_hosts=172.20.0.111 ,172.20.0.112 ,172.20.0.113 ,172.20.0.114

Notice that I’ve added all our JMeter server into JMeter configuration file. By default the configuration is stated as remote_hosts=127.0.0.1 .For this configuration, you just need to configure it under JMeter server that assign as Master

svg%3E

4. Testing Phase

As everything is done, let’s do test and compare results for single JMeter load testing and distributed JMeter load.

Before we start the test, let’s make the assumption for final result expection. For this test, we will try to execute a database query that called from a site. We will use the URL to access the site and include it inside JMX file to be executed by JMeter service. For this tutorial, we will not include the step on how to create a JMX file

Just to be clear, below are the simple query that we’ll use execute from database via web URL:
[root@jmeter01 ~]# mysql -u shahril -p -h 10.124.12.13
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 546695
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MySQL [(none)]> SELECT 1 FROM cassie_devdb.saml_users WHERE (username = '[email protected]') LIMIT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

FYI, you can use any query you like for this tutorial. As this query was not tune, it is expected to boost CPU resources when it’s been executed by multiple session which we will schedule using JMeter service

Now as everything prepared and understood, let’s start all JMeter server. Below are the command:
[root@jmeter01 ~]# $HOME/jmeter/bin/jmeter-server &
[1] 6149

svg%3E

To proceed with the test, let’s execute the JMX file that will trigger above query in single JMeter server as per below:
[root@jmeter01 /]# /root/jmeter/bin/jmeter -n -t /opt/jmeter/shahril_loadtest/testing.jmx

Notice above `testing.jmx` was the JMX file that contain the execution thread. Once above executed, you will see result as per screenshot below

svg%3E

Next, let’s run the same JMX file towards JMeter in distributed environment. Below are the steps:
[root@jmeter01 /]# /root/jmeter/bin/jmeter -n -t /opt/jmeter/shahril_loadtest/testing.jmx -R 172.20.0.111,172.20.0.112,172.20.0.113,172.20.0.114

Noted that the command fairly same with running in single phase, just need to add a flag of -R and added the other JMeter server to be included for execution. You can see the detail of listed flag provided by JMeter command as below:
[root@jmeter01 /]# /root/jmeter/bin/jmeter --help
_ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____
/ | _ / / ___| | | | ____| | | / | ____|_ _| ____| _
/ _ | |_) / _ | | | |_| | _| _ | | |/| | _| | | | _| | |_) |
/ ___ | __/ ___ |___| _ | |___ | |_| | | | | |___ | | | |___| _
/_/ __| /_/ _____|_| |_|_____| ___/|_| |_|_____| |_| |_____|_| _ 5.1.1 r1855137

Copyright (c) 1999-2019 The Apache Software Foundation

To list all command line options, open a command prompt and type:

jmeter.bat(Windows)/jmeter.sh(Linux) -?

--------------------------------------------------

To run Apache JMeter in GUI mode, open a command prompt and type:

jmeter.bat(Windows)/jmeter.sh(Linux) [-p property-file]

--------------------------------------------------

To run Apache JMeter in NON_GUI mode:
Open a command prompt (or Unix shell) and type:

jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file]

--------------------------------------------------

To run Apache JMeter in NON_GUI mode and generate a report at end :
Open a command prompt (or Unix shell) and type:

jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] -e -o [Path to output folder]

--------------------------------------------------
To generate a Report from existing CSV file:
Open a command prompt (or Unix shell) and type:

jmeter.bat(Windows)/jmeter.sh(Linux) -g [csv results file] -o [path to output folder (empty or not existing)]

--------------------------------------------------

To tell Apache JMeter to use a proxy server:
Open a command prompt and type:

jmeter.bat(Windows)/jmeter.sh(Linux) -H [your.proxy.server] -P [your proxy server port]

---------------------------------------------------

To run Apache JMeter in server mode:
Open a command prompt and type:

jmeter-server.bat(Windows)/jmeter-server(Linux)

---------------------------------------------------

Moving on, once the JMX file been executed under distributed environment, you will see result as per screenshot below

svg%3E

Great, now we’ve successfully run our test in both environment phase. To see the comparison differences, I’ve set up a monitoring dashboard powered by grafana .As this is just to show the result differences, we will not cover on how to setup Grafana as monitoring dashboard

Base on the CPU usage that taken from the target server that host our website, below are the result under single JMeter thread:

svg%3E

And below image are the result under distributed JMeter thread:

svg%3E

Clearly from above comparison, we can see that we manage to introduce more thread to be executed into the target server to see the limitation of an application can accept.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !