The ab command is a command line load testing and benchmarking tool for web servers that allows you to simulate high traffic to a website. The short definition form apache.org is:
ab – Apache HTTP server benchmarking tool
The acronym ab stands for Apache Bench where bench is short for benchmarking.
How To Install the ab Command
If you don’t already have the ab command on your system, you can easily install it on Debian/Ubuntu as it is part of the apache2-utils package.
sudo apt-get install apache2-utils
After installing the apache2-utils package, you have a series of add-on programs that are useful for any web server including the ab command.
Apache Bench Load Testing Tutorial
The simplest Apache bench test can be executed with the following command where:
- -n is the number of requests
- -c is the number of concurrent requests
ab -n 100 -c 10 https://example.com/
This will send a total of 100 requests to the website example.com with no more than 10 concurrent users making requests at once. Essentially, the ab command will initially make 10 concurrent requests to example.com, then once one of the requests is fulfilled, the 11th request will be made. This pattern will repeat until all 100 requests have been fulfilled.
If you would like to log the results from each individual request, you can do that with the -g argument:
ab -n 10000 -c 1000 -g out.txt https://example.com/
At the most basic level, this is probably the easiest way to conduct load testing for a website. You can monitor the resource usage on your website with the
htop command to see live memory usage and CPU utilization.
Please let me know if you have any questions about Apache Bench or load testing in general.