07.06.2023

Webserver Load testing

Why should you use tests

When website is rolls up from development environment to production, much real visitors generates server load and website performance may be different then you expect. To predict website behaviour you should simulate real loading on your test server.

Testing aims

The most important parameters of website working is:

Before testing

Before run the tests you should ensure that your server has enough system resources to handle all requests. Common "metrics" is available system memory and CPU loading. To check available RAM you can use built-in utility named free. Just run simple command:

free -m

In most uses cases server should has at least 25% free RAM, without swapping.

Situation with CPU loading will describe other built-in utility. Please run it to check:

top

System load average shouldn't excess 1*CPU cores quantity. E.g. if load average of 8-cores CPU excess 8.00 - you're in trouble.

Load simulation

To simulate real visitors you can use a few tools. Look at description below:

This tool allow you to make much simultaneous connections to the webserver. Just run:

ab -c <NUMBER_OF_SIMULTANEOUS_REQUESTS> -n <NUMBER_OF_TOTAL_REQUESTS> <WEBSITE_URL>

This is very similar with previous console tool. To install it just run package manager:

apt install siege

Then use the tool:

siege -t <TESTING_TIME> -c <NUMBER_OF_SIMULTANEOUS_REQUESTS> <WEBSITE_URL>

Other utility for testing is locust. It is test utility with web-interface. To install it please run:

pip3 install locust

Then download config file, edit it by your needs and run test:

wget https://raw.githubusercontent.com/locustio/locust/master/examples/browse_docs_test.py
sed 's|https://docs.locust.io/en/latest|<YOUR_DOMAIN>|g' browse_docs_test.py
locust -f browse_docs_test.py

Then you can open URL http://<YOUR_SERVER_IP>:8089 to see test results

Summary

In this article we described how to simulate production load on your server to test website.