How are your websites performing? You can open a web browser, point it to these sites and check that they work, but do you really take the time to test these sites to see if they meet your company’s (or your customers’) high performance standards? require? If you don’t know the answer to this question, you should start load testing the sites you develop or administer.
Before you think this is difficult or will require paying for a third-party service, think again. There are plenty of tools to help you do this job, many of which are open source and free. One of these open source tools is called Apache Bench.
Apache Bench is able to load test more than Apache web server because any HTTP server or even API (application programming interface) can be tested with this tool.
I want to show you how to install Apache Bench and use it to load test a website. I’ll demonstrate it on Ubuntu 22.04, but it can be installed on just about any Linux distribution. Be aware that Apache Bench is a command-line tool, but it’s actually quite simple to use.
That said, let’s get to work.
SEE: Recruitment kit: Back-end developer (TechRepublic Premium)
What you will need
To follow, you will need a running instance of Ubuntu Linux. It can be Ubuntu Server or Desktop and can be any version. You will also need a user with sudo privileges and a website to test.
How to Install Apache Bench
The first thing to do is to install Apache Bench. Log in to your Ubuntu Linux instance, open a terminal window and run the command:
sudo apt-get install apache2-utils -y
In case you are using an RHEL-based distribution, such as Fedora Linux, this command would be:
sudo dnf install httpd-tools -y
The installation should go smoothly. Once it’s done, you’re ready to test loading a website.
How to load a test with Apache Bench
The Apache Bench command requires a few options to run. The most commonly used options include:
- -n: The number of requests
- -c: the number of concurrent requests
- -H: add header
- -r: don’t leave socket gets errors
- -k: use the HTTP KeepAlive feature
- -p: File containing data to POST
- -t: The maximum time to spend on benchmarking
- -T: content-type header to use for POST/PUT data
A simple test would look like this:
ab -n 1000 -c 100 http://SERVER/
Where WAITER is the domain or IP address of the server.
The trailing / is required, otherwise the ab test will fail. Suppose you are currently testing a development website at IP address 192.168.1.11 and you want to run a simple ab load test. This command would be:
ab -n 1000 -c 100 http://192.168.1.11/
The results of this command might look like this:
HTML transferred: 10918000 bytes
Requests per second: 292.16 [#/sec] (mean)
Time per query: 342,282 [ms] (mean)
Time per request: 3.423 [ms] (average, for all concurrent queries)
Transfer rate: 3193.18 [Kbytes/sec] received
Connection time (ms)
minimum average[+/-sd] maximum median
Connect: 8 30 16.6 29 274
Salary: 19,301,106.9 268,734
Pending: 4,299,106.6 267,732
Total: 27,330,108.0 297,770
Percentage of requests served within a certain time (ms)
100% 770 (longest query)
Most outputs are pretty self-explanatory. The bottom half could use a little understanding. In the output you see above, 50% of requests took 297ms, 66% of requests took 312ms or less, and so on. Something is clearly wrong with this site, as response times should be faster.
Or, let’s say you have a specific site on a specific port that you want to test. This command might look like this:
ab -n 1000 -c 100 http://192.168.1.11:9443/
If you also want to add the gzip and deflate headers into the mix as well as KeepAlive and make sure the command doesn’t end on a socket receive error, this command could look like this:
ab -n 1000 -c 100 -H “Accept-Encoding: gzip, deflate” -rk http://192.168.1.11/
All of a sudden, you might see output that includes something like this:
Failed requests: 27
(Connection: 0, Receive: 0, Length: 27, Exceptions: 0)
Let’s strike a little harder and limit the time spent on benchmarking with a command like this:
ab -t 60 -n 10000 -c 100 http://192.168.1.11/
It will take a bit longer as we reach 10,000 requests and 100 concurrent requests.
And that’s about all you need to load test your web servers from the command line. To learn more about what the ab command can do, be sure to read the man page with the man ab command.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech tips for professionals from Jack Wallen.