ab 是一個性能測試工具,用來測試一個頁面每秒鐘能處理多少HTTP請求。
[root@localhost ~]$ yum install -y httpd-tools # 安裝ab工具
[root@localhost ~]$ ab -c 10 -n 1000 http://www.91cnm.com/ # 指定併發請求數爲10,總請求數爲1000,對http://www.91.cnm.com/進行壓力測試
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.91cnm.com (be patient)
Completed 100 requests # 已經完成了100個請求
Completed 200 requests # 已經完成了200個請求
Completed 300 requests
Completed 400 requests # 這個地方是關注點之一,如果全部完成了,說明服務器能扛住我們所指定的請求量
Completed 500 requests # 我們可以繼續增大請求數來進行測試,直到扛不住了就是最大的所能處理的請求了
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx # 所請求的服務端軟件
Server Hostname: www.91cnm.com # 所請求的服務端主機名
Server Port: 80 # 所請求的服務端端口
Document Path: / # 請求的URL資源
Document Length: 10507 bytes # 請求的頁面大小
Concurrency Level: 10 # 併發請求數,也就是我們用 -c 10 指定的數量
Time taken for tests: 43.339 seconds # 總訪問時間,也就是服務器處理完這些請求所花費的時間
Complete requests: 1000 # 請求成功的數量
Failed requests: 0 # 請求失敗的數量,這個地方也是關注點之一,如果出現有失敗的,說明有點扛不住了
Write errors: 0 # 網絡連接寫入錯誤數
Total transferred: 10645000 bytes # 請求的總數據大小(包括header頭信息)
HTML transferred: 10507000 bytes # 請求的HTML文檔的總數據大小
Requests per second: 23.07 [#/sec] (mean) # 平均每秒請求數,是總請求數除以處理完成這些請求數所花費的時間的結果,也是重要指標之一
Time per request: 433.387 [ms] (mean) # 表示用戶平均請求等待時間,參考:https://www.imooc.com/article/19952
Time per request: 43.339 [ms] (mean, across all concurrent requests) # 表示服務器平均請求處理時間,參考:https://www.imooc.com/article/19952
Transfer rate: 239.87 [Kbytes/sec] received # 平均每秒傳輸多少K,也就是服務器的帶寬了
Connection Times (ms)
min mean[+/-sd] median max
Connect: 150 164 32.4 168 1163
Processing: 150 265 307.8 168 2726
Waiting: 150 264 307.9 168 2726
Total: 300 429 311.4 336 2895
Percentage of the requests served within a certain time (ms)
50% 336 # 50%的請求數在336ms內返回
66% 338 # 66%的請求數在338ms內返回
75% 340
80% 341 # 這個地方也是關注點之一,我們不僅要扛住這麼多請求,而且要儘快地處理請求並響應回客戶端
90% 697
95% 1073
98% 1766
99% 1843
100% 2895 (longest request)