最後更新: 2019-06-12
介紹
ab - Apache HTTP server Benchmarking tool (ApacheBench)
目錄
- 安裝
- System Settings (nofile)
- Usage
- Useful options
- POST & PUT
- Example
安裝
# U12
apt-get install apache2-utils
獲得: /usr/bin/ab
# Rocky 8
dnf install httpd-tools # 會自動安了 apr, apr-util ...
System Settings (nofile)
在 benchmark 時見到
socket: Too many open files (24)
解決
[一次性]
ulimit -n 20000
[永久]
echo -ne "
* soft nofile 65536
* hard nofile 65536
" >> /etc/security/limits.conf
Usage
ab [options] [http[s]://]hostname[:port]/path
Example
# -n requests # Number of requests to perform
# -c concurrency # Number of multiple requests to make
ab -n 1000 -c 10 http://server/
Useful options
# Maximum number of seconds to wait before the socket timeout. Default is 30 seconds.
-s timeout
# Maximum number of seconds to spend for benchmarking. (This implies a -n 50000 internally)
-t timelimit
# Supply BASIC Authentication credentials to the server.
-A auth-username:password
# Add a Cookie: line to the request.
-C cookie-name=value
POST & PUT
-p postfile # File containing data to POST. Remember also to set -T
-u putfile # File containing data to PUT. Remember also to set -T
-T content-type # Content-type header for POSTing, eg. 'application/x-www-form-urlencoded'
Example
# 保持 100 條連線, 直到完成 4000 個連線
ab -n 10000 -c 100 https://datahunter.org/
Benchmarking datahunter.org (be patient) Completed 400 requests # 每 n/c report 1 次 Completed 800 requests ...
測試完成後
Concurrency Level: 100 Time taken for tests: 21.662 seconds Complete requests: 10000 Failed requests: 0 Non-2xx responses: 10000 Total transferred: 3980000 bytes HTML transferred: 0 bytes Requests per second: 461.65 [#/sec] (mean) Time per request: 216.616 [ms] (mean) Time per request: 2.166 [ms] (mean, across all concurrent requests) Transfer rate: 179.43 [Kbytes/sec] received
說明: Time per request
(mean)
# average amount of time it took for a 'concurrent group' of requests to process
Time taken for tests / (Complete requests /Concurrency Level) = 21662 / (10000/100) = 2.166 [ms]
(mean, across all concurrent requests)
average amount of time it took for a 'single' request
"Time taken for tests" / "Complete requests" = 21.662 / 10000 = 2.166 [ms]
/server-status
... 2.57 requests/sec - 275.3 MB/second - 107.1 MB/request - 27724.2 ms/request 102 requests currently being processed, 148 idle workers
"requests/sec" 與 "requests currently" 係有分別的
requests/sec
This is the average number of requests that the server is processing per second.
It is calculated over the lifetime of the server.
requests currently
This includes requests that are actively being processed
as well as requests that are in the server's queue waiting to be processed.
詳見: mod_status