How to Use the ab Command for Load Testing

Apache bench tutorial

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

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.

YouTube video

Please let me know if you have any questions about Apache Bench or load testing in general.

Facebook
Twitter
Pinterest
LinkedIn
Reddit

Meet Tony

Tony from Tony Teaches Tech headshot

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

Leave a Reply

Your email address will not be published. Required fields are marked *