The ab
command is a tool that is used to benchmark the performance of an Apache web server. It sends a specified number of requests to the server and measures the amount of time it takes for the server to respond. This tool is useful for testing the performance of a web server and identifying bottlenecks in the server’s configuration.
Overview
The ab
command is used by running the following command in a terminal:
ab [options] [http[s]://]hostname[:port]/path
The options that can be used with this command are described in the next section. The hostname
and path
arguments are required, while the port
argument is optional and defaults to port 80 for HTTP and port 443 for HTTPS.
Here is an example of how to use the ab
command to test the performance of a web server:
ab -n 100 -c 10 http://example.com/
This command will send 100 requests to the http://example.com/
URL with a concurrency level of 10. The output of the command will include statistics about the requests, including the total number of requests, the total time taken, and the average time per request.
Options
The following table lists the available options for the ab
command:
Option | Description |
---|---|
-n requests | Number of requests to perform |
-c concurrency | Number of multiple requests to make at a time |
-t timelimit | Maximum number of seconds to spend on benchmarking |
-p postfile | File containing data to POST |
-T content-type | Content-type header for POST data |
-k | Use HTTP KeepAlive feature |
-H header | Add header to request |
-A user-agent | User-Agent header for request |
-v verbosity | How much troubleshooting info to print |
-w | Print results in HTML format |
-s timeout | Maximum number of seconds to wait for a response |
-S | Do not display progress messages |
-r | Don’t exit on socket receive errors |
-X proxy:port | Use proxy server for request |
-V | Print version number and exit |
-h | Display usage information |
Troubleshooting tips
If the ab
command is not working as expected, there are a few common issues to check:
- Make sure that the server being tested is running and accessible from the machine running the
ab
command. - Check that the
hostname
andpath
arguments are correct and that the server is configured to serve requests at that URL. - If the command is taking a long time to complete, try reducing the number of requests or the concurrency level to see if that improves performance.
- If the command is failing with errors, check the output for any error messages and try to diagnose the issue based on those messages.
Notes
- The
ab
command is included with the Apache web server and does not need to be installed separately. - This command is not limited to testing Apache web servers and can be used to test any web server that supports HTTP or HTTPS requests.
- The
ab
command can generate a large amount of network traffic, so use caution when running it against production servers.