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.
The most important parameters of website working is:
- Latency - the time from user request to the server response;
- Server performance margin - the number of simultaneous requests server can handle. In case server is overloaded, user requests to the website will be places in the queue or even discards;
- Stability - how many requests are handled with predictable quality. This is so-called "percentile". E.g. 20 milliseconds first-byte-response 90th percentile (good work) means 90% of user requests will be "answered" in 20ms or less.
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:
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:
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.
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:
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
In this article we described how to simulate production load on your server to test website.