[root@nginx-server ~]# yum install httpd-tools
[root@nginx-server ~]# ab -n 2000 -c 2 http://127.0.0.1/
-n 總的請求數
-c 並發數
-n:即requests,用於指定壓力測試總共的執行次數
-c:即concurrency,用於指定的並發數
-t:即timelimit,等待響應的最大時間(單位:秒)
-b:即windowsize,TCP發送/接收的緩沖大小(單位:字節)
-p:即postfile,發送POST請求時需要上傳的文件,此外還必須設置-T參數
-u:即putfile,發送PUT請求時需要上傳的文件,此外還必須設置-T參數
-T:即content-type,用於設置Content-Type請求頭信息,例如:application/x-www-form-urlencoded,默認值為text/plain
-v:即verbosity,指定打印幫助信息的冗余級別
-w:以HTML表格形式打印結果
-i:使用HEAD請求代替GET請求
-x:插入字符串作為table標簽的屬性
-y:插入字符串作為tr標簽的屬性
-z:插入字符串作為td標簽的屬性
-C:添加cookie信息,例如:"Apache=1234"(可以重復該參數選項以添加多個)
-H:添加任意的請求頭,例如:"Accept-Encoding: gzip",請求頭將會添加在現有的多個請求頭之后(可以重復該參數選項以添加多個)
-A:添加一個基本的網絡認證信息,用戶名和密碼之間用英文冒號隔開
-P:添加一個基本的代理認證信息,用戶名和密碼之間用英文冒號隔開
-X:指定使用的和端口號,例如:"126.10.10.3:88"
-V:打印版本號並退出
-k:使用HTTP的KeepAlive特性
-d:不顯示百分比
-S:不顯示預估和警告信息
-g:輸出結果信息到gnuplot格式的文件中
-e:輸出結果信息到CSV格式的文件中
-r:指定接收到錯誤信息時不退出程序
-H:顯示用法信息,其實就是ab -help
2、內容解釋
Server Software: nginx/1.10.2 (服務器軟件名稱及版本信息)
Server Hostname: 192.168.1.106(服務器主機名)
Server Port: 80 (服務器端口)
Document Path: /index1.html. (供測試的URL路徑)
Document Length: 3721 bytes (供測試的URL返回的文檔大小)
Concurrency Level: 1000 (並發數)
Time taken for tests: 2.327 seconds (壓力測試消耗的總時間)
Complete requests: 5000 (的總次數)
Failed requests: 688 (失敗的請求數)
Write errors: 0 (網絡連接寫入錯誤數)
Total transferred: 17402975 bytes (傳輸的總數據量)
HTML transferred: 16275725 bytes (HTML文檔的總數據量)
Requests per second: 2148.98 [#/sec] (mean) (平均每秒的請求數) 這個是非常重要的參數數值,服務器的吞吐量
Time per request: 465.338 [ms] (mean) (所有並發用戶(這里是1000)都請求一次的平均時間)
Time request: 0.247 [ms] (mean, across all concurrent requests) (單個用戶請求一次的平均時間)
Transfer rate: 7304.41 [Kbytes/sec] received 每秒獲取的數據長度 (傳輸速率,單位:KB/s)
...
Percentage of the requests served within a certain time (ms)
50% 347 ## 50%的請求在347ms內返回
66% 401 ## 60%的請求在401ms內返回
75% 431
80% 516
90% 600
95% 846
98% 1571
99% 1593
100% 1619 (longest request)
注意事項
● 測試機與被測試機要分開
● 不要對線上的服務器做壓力測試
[root@nginx-server ~]# ab -n 50 -c 2 http://www.testpm.cn/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.testpm.cn (be patient).....done
Server Software: nginx/1.16.0
Server Hostname: www.testpm.cn
Server Port: 80
Document Path: /
Document Length: 612 bytes
Concurrency Level: 2
Time taken for tests: 2.724 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 42250 bytes
HTML transferred: 30600 bytes
Requests per second: 18.35 [#/sec] (mean)
Time per request: 108.968 [ms] (mean)
Time per request: 54.484 [ms] (mean, across all concurrent requests)
Transfer rate: 15.15 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 42 52 17.3 46 137
Processing: 43 54 20.8 47 170
Waiting: 42 53 20.7 47 170
Total: 84 106 28.9 93 219
Percentage of the requests served within a certain time (ms)
50% 93
66% 96
75% 101
80% 130
90% 153
95% 161
98% 219
99% 219
100% 219 (longest request)