ApacheBench (ab) is a command-line tool used for performing load testing and benchmarking of web servers. It allows you to simulate concurrent user requests to a specified URL, helping you measure server performance, identify bottlenecks, and understand its capacity under stress.
ApacheBench provides various options to customize your load tests. Here are some common examples:
To send a specific number of requests with a defined concurrency
level, use the -n (number of requests) and
-c (concurrency) flags.
# To send 100 requests with a concurency of 50 requests to a URL:
ab -n 100 -c 50 <url>
If you want to test your server's performance over a period of time,
use the -t (time limit in seconds) flag along with the
concurrency setting.
# To send requests for 30 seconds with a concurency of 50 requests to a URL:
ab -t 30 -c 50 <url>
-
-n requests: The total number of requests to perform for the benchmarking session. -
-c concurrency: The number of multiple requests to perform at a time. -
-t seconds: The maximum amount of time in seconds to spend benchmarking. -k: Enable the HTTP Keep-Alive feature.-
-H header: Add arbitrary header line to the request.
Load testing with ApacheBench is crucial for ensuring your web application can handle expected traffic. It helps in:
- Performance Measurement: Gauge response times and throughput.
- Capacity Planning: Determine how many users your server can support.
- Bottleneck Identification: Pinpoint areas of your infrastructure that are struggling under load.
- Regression Testing: Ensure performance doesn't degrade after code changes.
- ApacheBench (ab) Official Documentation
- MDN Web Docs: HTTP Performance
- WebPageTest (for more advanced web performance testing)