ab

web serverlinux
The ab command is one of the most frequently used commands in Linux/Unix-like operating systems. ab The ab (Apache Benchmark) command is a performance testing tool for HTTP servers. It shows how your Apache installation performs by generating load to the server. This tool quickly identifies how many requests per second your Apache server is capable of handling.

Quick Reference

Command Name:

ab

Category:

web server

Platform:

linux

Basic Usage:

ab [options] [arguments]

Common Use Cases

  • 1

    Web server performance testing

    Benchmark HTTP server performance by measuring requests per second

  • 2

    Load testing

    Simulate multiple concurrent users to test server capacity under load

  • 3

    Performance optimization

    Identify bottlenecks and optimize web server configurations

  • 4

    Capacity planning

    Determine server capacity requirements for production deployments

Syntax

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

Options

Option Description
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. wait for responses
-b windowsize Size of TCP send/receive buffer, in bytes
-p postfile File containing data to POST
-u putfile File containing data to PUT
-T content-type Content-type header for POST/PUT data
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Do HEAD requests instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, e.g. 'Apache=1234' (repeatable)
-H attribute Add arbitrary header (repeatable)
-A attribute Add Basic WWW Authentication, attribute is username:password
-P attribute Add Basic Proxy Authentication, attribute is username:password
-X proxy:port Proxyserver and port number to use
-k Use HTTP KeepAlive feature
-g gnuplot-file Output collected data to gnuplot format file
-e csv-file Output CSV file with percentages served
-S Do not display error messages and warnings
-q Do not display progress while running
-h Display usage information

Examples

How to Use These Examples

The examples below show common ways to use the ab command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

Basic Examples:

Perform 100 requests with 10 concurrent connections
ab -n 100 -c 10 http://example.com/
Test HTTPS site
ab -n 1000 -c 50 https://example.com/
Test a specific page
ab -n 500 -c 25 http://example.com/about.html
Output results to a file
ab -n 100 -c 10 -g results.tsv http://example.com/

Advanced Examples:

Use a POST request with data
ab -n 100 -c 10 -p post.txt -T 'application/x-www-form-urlencoded' http://example.com/form
Set a timeout for requests
ab -n 100 -c 10 -t 2 http://example.com/
Use HTTP Keep-Alive
ab -n 100 -c 10 -k http://example.com/
Use HTTP Basic Authentication
ab -n 100 -c 10 -A username:password http://example.com/
Test with custom headers
ab -n 100 -c 10 -H "Accept-Encoding: gzip" http://example.com/

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Understanding the Results:

The output from ab provides several important metrics:

  • Server Software: The web server software and version
  • Document Path/Length: The requested URL path and size of the response
  • Concurrency Level: The number of concurrent clients used during the test
  • Complete requests: The number of successfully completed HTTP requests
  • Failed requests: The number of requests that were considered a failure
  • Requests per second: The number of requests per second the server was able to handle (this is the benchmark number)
  • Time per request: The average time spent per request
  • Transfer rate: The rate at which data was transferred from the server to the clients
  • Connection Times: A breakdown of how long different phases of the HTTP transaction took
  • Percentage of requests served within a certain time: A histogram showing response time distribution

Tips:

  • Start with a small number of requests and concurrency to avoid overwhelming the server
  • Use the -k option (KeepAlive) to simulate more realistic browser behavior
  • Use -v 2 or -v 3 for more verbose output when debugging issues
  • The -g option allows you to save data for visualization with gnuplot
  • Remember that benchmarking from the same machine that hosts the web server can give misleading results
  • When testing production servers, be careful not to disrupt service for real users
  • Include proper warm-up time before taking measurements for more accurate results
  • Consider using a more advanced benchmarking tool like JMeter or wrk for complex scenarios

Common Use Cases

Web server performance testing

Benchmark HTTP server performance by measuring requests per second

Load testing

Simulate multiple concurrent users to test server capacity under load

Performance optimization

Identify bottlenecks and optimize web server configurations

Capacity planning

Determine server capacity requirements for production deployments

Regression testing

Compare performance before and after configuration changes

Related Commands

These commands are frequently used alongside ab or serve similar purposes:

Use Cases

1

Web server performance testing

Benchmark HTTP server performance by measuring requests per second

2

Load testing

Simulate multiple concurrent users to test server capacity under load

3

Performance optimization

Identify bottlenecks and optimize web server configurations

4

Capacity planning

Determine server capacity requirements for production deployments

5

Regression testing

Compare performance before and after configuration changes

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the ab command works in different scenarios.

$ ab
View All Commands