How to Test Load Balancing on AccuWeb.cloud?
As your project gains popularity and attracts more visitors, you may encounter the challenge of needing to boost your hardware’s performance to handle and quickly serve all incoming user requests.
While adding more resources can temporarily alleviate the strain and prevent server failure, it doesn’t address the underlying problem. Therefore, implementing a clustering solution with built-in automatic load balancing becomes essential.
Adjusting your application cluster on the platform is straightforward. Simply add additional application server instances to your environment using the topology wizard. Additionally, an NGINX load balancer will be automatically enabled in front of your project.
This load balancer will ensure even distribution of traffic across the specified number of application server nodes, thanks to its load balancing capabilities.
This approach significantly boosts your application’s performance, allowing it to handle a greater number of requests simultaneously. Additionally, it reduces the risk of downtime; if one server fails, the others will continue to operate, maintaining accessibility.
To demonstrate the efficiency of this setup, we will guide you through performing load balancing tests using the ApacheBench (ab) tool. ApacheBench offers a range of options for testing a server’s capacity to handle varying and increasing loads. While it was originally designed for testing Apache installations, it can be used to benchmark any HTTP server.
Let’s begin the real-time testing.
Set Up an Environment and Deploy Your Application
Step 1. Log in to the platform and select the “Create Environment” button located in the upper left corner of the dashboard.
Step 2. Access the platform and click on the “Create Environment” button found in the top-left corner of the dashboard.
To test the Apache PHP server load, choose it from the options and adjust the resource limits using the cloudlet sliders. Next, assign a Public IP address to the server and enter a name for the new environment (e.g., loadbalancer). Finally, click on the Create button to proceed.
Step 3. Your environment will appear on the dashboard in just a minute.
Use the default HelloWorld.zip package and Deploy it to your desired environment by clicking the corresponding button. “Once the environment has been set up successfully, verify the deployment within the interface.”
Control Point Testing
To establish a baseline for comparison, we will conduct a control point test using the created environment with a single application server node.
As mentioned earlier, we will utilize the ApacheBench (ab) tool for this task. The tool generates a single-threaded load by sending a specified number of concurrent requests to a server.
Here are the steps to follow:
Step 1. ApacheBench is included in the standard Apache source distribution.
If you don’t have it yet, run the following command in your terminal to install it (or skip this step if you already have it).
apt-get install apache2-utils
Please wait until the installation process is successfully finished.
Step 2. Next, enter the following command in the terminal:
ab -n 500 -c 10 -g res1.tsv {URL_to_your_env}
Step 3. Click on the “Open in Browser” button next to your environment and then copy the URL from the browser’s address bar.
This command will send a total of 500 requests to the specified environment, with each batch consisting of 10 concurrent requests at a time. All results will be saved in the res1.tsv file located in your home folder.
If you prefer to change the file location, specify the full path to the desired directory.
This test may require some time to complete, depending on the parameters you’ve configured, so please be patient.
Modify the Environment Configuration
Step 1. Return to the platform dashboard and select “Change environment topology” for your balancer environment.
Step 2. In the “Environment topology” window that appears, add additional application servers (e.g., another Apache instance) using the + button in the Horizontal Scaling section of the wizard.
Enable the Public IP feature and specify the resource limits for the automatically added NGINX load balancer node, which acts as the entry point for your application. Click Apply to confirm and proceed with the changes.
Step 3. After successfully applying all the necessary changes, you need to disable sticky sessions for the balancer server. Otherwise, requests from the same IP address will always be directed to the same application server instance.
To do this, click on the Config button next to the NGINX node.
Step 4. Navigate to the conf > nginx.conf file. Since it’s not editable directly, copy all its contents. Paste these contents into the nginx.conf file, which is located in the same folder. Replace the line include /etc/nginx/nginx.conf; with the pasted content from
Step 5. Next, locate the two instances of the sticky path parameter in the code within the DEFAULT UPSTREAM and UPSTREAMS LIST sections, and comment them out as shown below.
Step 6. Save the changes you’ve made and then restart the NGINX server.
Testing Balancer and Compare Results
Return to your terminal and rerun the ApacheBench (ab) testing with the same parameters as before, but specify a different file name for the results (e.g., res2.tsv)
ab -n 500 -c 10 -g res2.tsv {URL_to_your_env}
By following these steps, you’ll be able to install Gnuplot on your system and utilize it to create insightful graphs for your data analysis needs.
gnuplot
To prepare for creating a graph with Gnuplot, follow these steps to set up the parameters:
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 '\tM
To compose the graph using Gnuplot, proceed with the following steps:
plot “/home/res1.tsv” every ::2 using 5 title ‘Single Apache Server’ with lines, “/home/res2.tsv” every ::2 using 5 title ‘Two Apache Servers with NGINX LB’ with lines