← 返回命令列表

Linux command

ab 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Benchmark

ab -n 100 -c 10 [http://example.com/]

POST

ab -n 100 -c 10 -p [data.json] -T application/json [http://example.com/api]

Example

ab -n 100 -c 10 -k [http://example.com/]

Example

ab -n 100 -c 10 -H "Authorization: Bearer [token]" [http://example.com/]

说明

ab (Apache Benchmark) is a command-line tool for benchmarking HTTP servers. It generates load by sending multiple requests to a specified URL and measures server response times, throughput, and other performance metrics. The tool reports statistics including requests per second, time per request, transfer rate, and connection times broken down by percentiles. It supports both HTTP and HTTPS, custom headers, POST data, cookies, and HTTP authentication.

参数

-n _requests_
Number of requests to perform for the benchmarking session
-c _concurrency_
Number of multiple requests to perform at a time (simultaneous connections)
-t _timelimit_
Maximum number of seconds to spend benchmarking (implies -n 50000)
-k
Enable HTTP KeepAlive feature (persistent connections)
-p _file_
File containing data to POST
-T _content-type_
Content-type header for POST/PUT data
-H _header_
Append extra header to the request (repeatable)
-A _auth_
HTTP Basic Authentication credentials (user:password)
-C _cookie_
Add a Cookie header (name=value)
-s _timeout_
Maximum seconds to wait before socket times out (default 30)
-v _verbosity_
Verbosity level (2=warnings, 3=response codes, 4+=headers)
-u _file_
File containing data to PUT (also set -T)
-X _proxy:port_
Use a proxy server for the requests
-e _csv-file_
Write a CSV file with response time percentiles (1%-100%)
-g _gnuplot-file_
Write measured values as a gnuplot/TSV file
-i
Use HEAD requests instead of GET
-l
Accept variable document length (for dynamic pages)
-r
Don't exit on socket receive errors
-q
Suppress progress messages on stderr (for >150 requests)

FAQ

What is the ab command used for?

ab (Apache Benchmark) is a command-line tool for benchmarking HTTP servers. It generates load by sending multiple requests to a specified URL and measures server response times, throughput, and other performance metrics. The tool reports statistics including requests per second, time per request, transfer rate, and connection times broken down by percentiles. It supports both HTTP and HTTPS, custom headers, POST data, cookies, and HTTP authentication.

How do I run a basic ab example?

Run `ab -n 100 -c 10 [http://example.com/]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -n _requests_ do in ab?

Number of requests to perform for the benchmarking session