ab
Benchmark HTTP server performance
TLDR
Execute 100 HTTP GET requests to a given URL
Execute 100 HTTP GET requests, in concurrent batches of 10, to a URL
Execute 100 HTTP POST requests to a URL, using a JSON payload from a file
Use HTTP [k]eep-Alive, i.e. perform multiple requests within one HTTP session
Set the maximum number of seconds ([t]imeout) to spend for benchmarking (30 by default)
Write the results to a CSV file
SYNOPSIS
ab [options] [http[s]://]hostname[:port]/path
Example:ab -n 1000 -c 10 https://example.com/index.html
PARAMETERS
-n requests
Number of requests to perform for the benchmarking session.
-c concurrency
Number of multiple requests to perform at a time.
-t seconds
Maximum number of seconds to spend for benchmarking. Requests will be aborted after this time.
-p postdata_file
File containing data to POST. Use with -T
to specify Content-Type.
-T content-type
Content-type header to use for POST/PUT data. E.g., application/json
.
-v verbosity
How much information to print. Levels 0 to 4 (more verbose).
-k
Use HTTP KeepAlive feature, i.e., send multiple requests within one HTTP session.
-H header
Add arbitrary header line to the request. E.g., 'Authorization: Bearer xyz'
.
-A auth-string
Add Basic WWW Authentication header to requests. Format: user:password
.
-X proxy[:port]
Use specified proxy server for requests.
-i
Perform HEAD requests instead of GET.
-e csv_file
Output results to a CSV file, useful for spreadsheet analysis.
-g gnuplot_file
Output results in gnuplot format, for graphical plotting.
-s timeout
Seconds to wait for the entire request to complete. Default is 30 seconds.
-S
Do not display confidence intervals and warnings for latency.
DESCRIPTION
ab
, short for ApacheBench, is a command-line tool designed for benchmarking HTTP servers. It measures the performance of web servers by sending a specified number of concurrent requests to a URL and reporting various metrics. These metrics include requests per second, time per request, transfer rate, latency, and throughput.
It's commonly used by developers and system administrators to understand how many requests an Apache (or any HTTP-compliant) web server can handle within a given timeframe, helping to identify potential bottlenecks, test server configurations, and evaluate the impact of code changes on server performance. While it's part of the Apache HTTP Server distribution, it can be used to benchmark any web server capable of handling HTTP/1.0 and HTTP/1.1 requests. Its simplicity and speed make it ideal for quick performance checks.
CAVEATS
ab
operates from a single client machine, which may not accurately simulate distributed user load from multiple geographical locations. The client machine itself can become a bottleneck if it lacks sufficient resources (CPU, network bandwidth) to generate the desired load. It primarily supports HTTP/1.0 and HTTP/1.1, potentially missing out on benefits or nuances of newer protocols like HTTP/2 or HTTP/3. ab
cannot execute JavaScript or simulate complex user behavior (e.g., login, navigate, click), making it unsuitable for advanced end-to-end user experience testing. It also does not fetch embedded resources (images, CSS, JS), only the specified URL.
OUTPUT INTERPRETATION
ab
provides a summary of its test run, including the total number of requests, failed requests, transferred data, and most importantly, throughput (requests per second) and time per request (mean, median, min/max). It also presents a percentage served table, showing the latency distribution (e.g., 50% of requests completed within X ms, 90% within Y ms), which is crucial for understanding response time consistency and identifying outliers.
BEST PRACTICES
For accurate results, run ab
from a different machine than the server being tested to avoid client-side resource contention. Perform multiple runs to account for network variability and server warm-up. Ensure the test URL accurately reflects the resource you intend to benchmark (e.g., a dynamic page vs. a static file). Avoid running overly aggressive tests that might degrade the performance of other services on the same network or even trigger security countermeasures.
HISTORY
ab
is an integral part of the Apache HTTP Server distribution. It was developed by the Apache Software Foundation community as a simple and quick utility for testing the performance of web servers. Its development has been primarily driven by the needs of the Apache project, focusing on efficient HTTP/1.0 and HTTP/1.1 benchmarking. While ApacheBench itself has seen incremental updates over the years, its core functionality and usage remain consistent, reflecting its purpose as a straightforward command-line utility for performance assessments.
SEE ALSO
wrk(1): A modern HTTP benchmarking tool capable of generating significant load., siege(1): HTTP regression testing and benchmarking utility., curl(1): Transfer data from or to a server, often used for testing HTTP endpoints., wget(1): Non-interactive network downloader, useful for simple HTTP testing.