📘 Post

Mastering Apache Benchmark (ab) for Effective Load Testing

12/18/2024 By Sanchit Agrawal 2 min read 👁 626 views Updated 08/21/2026

Mastering Apache Benchmark Commands and Parameters

The Apache Benchmark tool (ab) is used to perform simple load testing on an HTTP web server. It provides insights into how many requests per second the server can handle, the average time taken for requests, and other performance metrics.

Basic Syntax – Mastering Apache Benchmark

Command
ab [options] [http[s]://]hostname[:port]/path

Mastering Apache Benchmark

Basic Options

  • -n requests: Specifies the total number of requests to perform for the benchmarking session. By default, ab will execute one request.
Command
ab -n 1000 http://example.com/
Mastering Apache Benchmark
Mastering Apache Benchmark
  • -c concurrency: Specifies the number of multiple requests to perform at a time. The default is one request at a time.
Command
ab -n 1000 -c 50 http://example.com/
image
image
  • -t timelimit: Specifies a timelimit for the benchmarking session. The implied number of requests (-n) is then defined by the number of requests ab can perform in the given time.
Command
ab -t 60 http://example.com/
  • -s timeout: Specifies a timeout in seconds for each request. Default is 30 seconds.
Command
ab -s 120 -n 1000 http://example.com/
  • -q: Reduces output. When present, only the result summary is shown.
Command
ab -q -n 1000 -c 50 http://example.com/
image
image

Mastering Apache Benchmark

HTTP Method Options

  • -m method: Specifies the HTTP method to use in the requests. The default is GET.
Command
ab -n 1000 -c 50 -m POST http://example.com/
  • -p postfile: Indicates the file containing data to POST. Must be used with -T.
Command
ab -n 1000 -c 50 -p postdata.txt -T application/x-www-form-urlencoded http://example.com/
  • -u putfile: Indicates the file containing data to PUT. Must be used with -T.
Command
ab -n 1000 -c 50 -u putdata.txt -T application/x-www-form-urlencoded http://example.com/
  • -T content-type: Specifies the content-type header for POST/PUT data. Default is text/plain.
Command
ab -n 1000 -c 50 -p postdata.txt -T application/json http://example.com/

Mastering Apache Benchmark

Additional Options

  • -v verbosity: Sets the verbosity level. Acceptable values are 1, 2, or 4. Default is 1.
Command
ab -v 2 -n 1000 -c 50 http://example.com/
  • -C cookie-name=value: Adds a cookie to the request.
Command
image
image
  • -H header: Adds an arbitrary header line. You can use this option multiple times to add multiple headers.
Command
  • -A auth-username:password: Adds basic authentication credentials.
Command
ab -n 1000 -c 50 -A admin:password http://example.com/
  • -P proxy-auth-username:password: Adds proxy authentication credentials.
Command
ab -n 1000 -c 50 -P proxyuser:password http://example.com/
  • -X proxy:port: Specifies a proxy server and port to send requests through.
Command
ab -n 1000 -c 50 -X proxy.example.com:8080 http://example.com/
  • -k: Enables HTTP KeepAlive, sending multiple requests over a single connection.
Command
ab -n 1000 -c 50 -k http://example.com/
  • -g gnuplot-file: Writes all measured values to a gnuplot file, which can be used for further analysis or graphing.
Command
ab -n 1000 -c 50 -g output.gnuplot http://example.com/
  • -e csv-file: Outputs results in CSV format.
Command
ab -n 1000 -c 50 -e output.csv http://example.com/

Example Commands

Basic Load Test

Perform 1000 requests to the specified URL with a concurrency of 50.

Command
ab -n 1000 -c 50 http://example.com/
image
image

POST Request with Data from File

Send 500 POST requests with data from a file.

Command
ab -n 500 -c 10 -p postdata.txt -T application/x-www-form-urlencoded http://example.com/api

Benchmarking with HTTP Authentication

Perform 200 requests using basic authentication.

Command
ab -n 200 -c 20 -A admin:password http://example.com/secure

Using a Proxy Server

Benchmark through a proxy server at proxy.example.com:8080.

Command
ab -n 1000 -c 50 -X proxy.example.com:8080 http://example.com/

Output Results to a CSV File

Generate a CSV file with the results of 1000 requests.

Command
ab -n 1000 -c 50 -e results.csv http://example.com/
image
image

Summary – Mastering Apache Benchmark

ab (Apache Benchmark) is a powerful and straightforward tool for performing load testing on HTTP servers. It offers various options to customize requests, simulate multiple users, and analyze server performance under load. Understanding and utilizing the available commands and parameters can help you conduct effective performance testing and identify potential bottlenecks in your web applications.

Mastering Apache Benchmark (ab) for Effective Load Testing

This article provided insights on the topic. For latest updates and detailed guides, stay connected with Sanchit Gurukul.

Disclaimer: This article may contain information that was accurate at the time of writing but could be outdated now. Please verify details with the latest vendor advisories or contact us at admin@sanchitgurukul.com.

Your feedback matters

Was this post helpful?

0 reactions

SanchitGurukul — Technology • Education • Innovation

Discussion

0 approved comments

No approved comments yet. You can start the discussion below.

Leave a Comment

No login is required. Name and email are used for moderation/security. Your email is never displayed publicly. All comments require administrator approval.

This field is not used to determine whether a comment is safe.

Plain text only. File uploads, scripts, executable code, abuse and spam are not accepted.


Discover more from SanchitGurukul

Subscribe to get the latest posts sent to your email.

Share this article

Help others find this guide.

Namaste! I’m SG Saarthi 👋Need help learning or finding something?

Discover more from SanchitGurukul

Subscribe now to keep reading and get access to the full archive.

Continue reading