How to Test Load Balancing

When your project becomes highly demanded and visited, you face a problem – necessity to increase your hardware productivity, as it should be able to handle and rapidly serve all the incoming users’ requests. Adding more resources will temporarily improve the situation, saving your server from failure, but it won’t solve the root issue. And this results in the need to set up a clustering solution with an embedded automatic load balancing.

Application cluster adjusting is quite easy with the platform – just add a few more application server instances to your environment via the topology wizard. In addition, you’ll automatically get the NGINX-balancer server enabled in front of your project. It will be responsible for the even distribution of load among the stated number of app server nodes, achieved through load balancing.

NGINX load balancer

In this way, your application's performance improves significantly, increasing the number of requests that can be served at once. As a nice bonus, you reduce the risk of app inaccessibility, since if one server fails, the rest continue working.

In order to prove that this scheme is efficient, we’ll show you how to perform the load balancing testing with the help of the ApacheBench (ab) tool. It provides several options for testing the servers’ ability to cope with increasing, variable load. Though AB was designed for Apache installation testing, it can be used to benchmark any HTTP server.

So, let’s get started and test it in real time.

1. Log into the platform and click the Create environment button in the upper left corner of the dashboard.

create environment

2. The Environment topology dialog window will instantly appear. Here you can choose the desired programming language, application/web server, and database.

As we are going to test the Apache PHP server loading, select it and specify the resource usage limits by means of the cloudlets sliders. Then attach the Public IP address for this server and type the name of a new environment (e.g., balancer). Click Create.

environment wizard

3. In just a minute, your environment will appear on the dashboard.

balancer environment created

4. Once the environment is successfully created, you can deploy your application to it. Here we’ll use the default HelloWorld.zip package, so you just need to deploy it to the desired environment with the corresponding button and confirm the deployment in the opened frame.

deploy hello world application

To analyze the results you’ll need something to compare them with, so let’s make a control point test, using the created environment with just a single application server node.

As it was mentioned above, we’ll use the ApacheBench (ab) tool for these purposes. It can generate a single-threaded load by sending the stated number of concurrent requests to a server.

So, follow the steps below.

1. ApacheBench is a part of the standard Apache source distribution, so if you still don’t have it, run the following command through your terminal (or skip this step if you do).

1
apt-get install apache2-utils

Wait until the installation is successfully completed.

Note: Detailed information on all further ab commands can be found at this link.

2. Enter the next line in the terminal:

1
ab -n 500 -c 10 -g res1.tsv {URL_to_your_env}

Substitute the {URL_to_your_env} part with a link to your environment (e.g. https://balancer.jelastic.com/ in our case). In order to get it, click the Open in Browser button next to your environment and copy the corresponding URL from the browser’s address bar.

open in browser

The specified command will send a total of 500 requests to the stated environment, divided into packs of 10 concurrent requests. All the results will be stored in the res1.tsv file inside your home folder (or enter the full path to the desired directory if you would like to change the file location).

Also, you can specify your custom parameters for the abovementioned command if you want.

control point testing

This test may take some time depending on the parameters you’ve set; be patient.

3. The created file with results should look like the image below:

control point result

1. Return to the platform dashboard and click Change environment topology for your balancer environment.

change environment topology

2. Within the opened Environment topology frame, add more application servers (e.g. one more Apache instance) – use the + button in the Horizontal scaling wizard section for that. Then enable the Public IP feature and state the resource limits for the automatically added NGINX-balancer node, as it becomes the entry point of your application. Click Apply to proceed.

environment topology with balancer

3. When all of the required changes are successfully applied, you should disable the sticky sessions for the balancer server. Otherwise, all requests from a single IP address will be redirected to the same instance of the application server.

Therefore, click the Config button next to the Nginx node.

NGINX config

4. Navigate to the conf > nginx-jelastic.conf file. It’s not editable, so copy all its content and paste it to the nginx.conf file (located in the same folder) instead of include /etc/nginx/nginx-jelastic.conf; line (circled at the following image).

adjust nginx.conf

5. Then, find two mentions of the sticky path parameter in the code (in the DEFAULT UPSTREAM and UPSTREAMS LIST sections) and comment them as it is shown below.

disable sticky session
Note: Don’t miss the closing curly braces after those sticky path strings; they should be uncommented.

6. Save the changes applied and restart the NGINX server.

NGINX node restart

Now let’s proceed directly to load balancing testing.

1. Switch back to your terminal and run the ab testing again with the same parameters (except the file with results – specify another name for it, e.g. res2.tsv).

1
ab -n 500 -c 10 -g res2.tsv {URL_to_your_env}
load balancing testing

2. In order to clarify the obtained results, we’ll use the freely distributed gnuplot graphs utility. Install it (if you haven’t done this before) and enter its shell with a gnuplot command.

gnuplot graphs utility

3. After that, you need to set up the parameters for our future graph:

1
2
3
4
5
6
7
set size 1, 1
set title "Benchmark testing"
set key left top
set grid y
set xlabel 'requests'
set ylabel "response time (ms)"
set datafile separator 't'
set gnuplot parameters

4. Now you’re ready to compose the graph:

1
plot "/home/res1.tsv" every ::2 using 5 title 'single server' with lines, "/home/res2.tsv" every ::2 using 5 title 'two servers with LB' with lines

This plot command will build 2 graphs (separated with a comma in the command body). Let’s consider the used parameters in more detail:

  • “/home/resN.tsv” represents paths to the files with your testing results
  • every ::2 operator defines that gnuplot will start building from the second row (i.e. the first row with headings will be skipped)
  • using 5 means that the fifth column (the total response time) will be used for graph building
  • title ‘N’ option sets the particular graph name for the easier separation of the test results
  • with lines is used for our graph to be a solid line
compose graphs

You’ll get an automatically created and opened image similar to the following:

load balancing result graph

Due to the specified options, the red graph shows the performance of a single Apache server without a balancer (control point testing results), and the green one shows the performance of two servers with an NGINX load balancer (the second testing phase results).

Note: The received testing results (response time for each sent request) are shown in ascending order, i.e., not chronologically.

As you can see, while serving low load, both configurations’ performance is almost the same, but as the number of requests increases, the response time for an environment with a single app server instance grows significantly, resulting in serving fewer requests simultaneously. So, if you expect a high load on your application server, increasing the number of its instances in a bundle with a balancer server is the best way to keep your customers happy.

Enjoy all the advantages of the Cloud!

Share this:
FacebookXWhatsAppTelegramLinkedInGmailCopy Link
Updated on March 10, 2026
Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support