天天看點

ab 壓力測試及結果分析

介紹及原理

Apache Bench簡稱

ab

,它是Apache自帶的壓力測試工具。ab非常實用,它不僅可以對Apache伺服器進行網站通路壓力測試,也可以對或其它類型的伺服器進行壓力測試。

安裝

  • Ubuntu
sudo apt-get install apache2-utils
           
  • ContOS
yum -y install httpd-tools
           
  • ab -V

    驗證是否安裝完成
[email protected]:~# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
           

壓力測試

ab 常用參數

  • -n :總共的請求執行數,預設是1;
  • -c: 并發數,預設是1;
  • -t:測試所進行的總時間,秒為機關,預設50000s
  • -p:POST時的資料檔案
  • -w: 以HTML表的格式輸出結果

輸入指令

ab -n 10000 -c 1000 http://192.168.88.10/index.html

開始測試

[email protected]:/home/vagrant# ab -n 10000 -c 1000 http://192.168.88.10/index.html
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.88.10 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx/1.14.0	#被測試的伺服器所用的軟體資訊
Server Hostname:        192.168.88.10	#被測主機名
Server Port:            80				#被測主機的服務端口号,一般http請求的預設端口号是80,https預設使用443端口

Document Path:          /index.html		#請求的具體檔案路徑
Document Length:        612 bytes		#請求的index.html檔案大小

Concurrency Level:      1000			#并發級别,也就是并發數,請求中-c參數指定的數量
Time taken for tests:   36.639 seconds	#整個測試持續的時間
Complete requests:      10000			#本次測試總共發起的請求數量
Failed requests:        0				#失敗的請求數量,因網絡原因或伺服器性能原因,發起的請求并不一定全部成功,通過該數值和Complete requests相除可以計算請求的失敗率,作為測試結果的重要參考
Total transferred:      8540000 bytes	#總共傳輸的資料量,指的是ab從被測伺服器接收到的總資料量,包括index.html的文本内容和請求頭資訊
HTML transferred:       6120000 bytes	#從伺服器接收到的index.html檔案的總大小,等于Document Length*Complete requests=612 bytes*10000=6120000 bytes
Requests per second:    272.93 [#/sec] (mean)	#平均(mean)每秒完成的請求數:QPS,這是一個平均值,等于Complete requests/Time taken for tests=10000/36.639=272.93
Time per request:       3663.885 [ms] (mean)	#平均每個請求處理時間為3663.885毫秒 注:這裡将一次1000個并發請求看成一個整體
Time per request:       3.664 [ms] (mean, across all concurrent requests)	#平均每個并發請求處理時間 為3.664毫秒 
Transfer rate:          227.62 [Kbytes/sec] received	#網絡傳輸速度,對于大檔案的請求測試,這個值很容易成為系統瓶頸所在。要确定該值是不是瓶頸,需要了解用戶端和被測伺服器之間的網絡情況,包括網絡帶寬和網卡速度等資訊

Connection Times (ms)
              min  mean[+/-sd] median   max		#表中min表示最小值; mean表示平均值;[+/-sd]表示标準差(Standard Deviation) ,也稱均方差(mean square error),這個概念在中學的數學課上學過,表示資料的離散程度,數值越大表示資料越分散,系統響應時間越不穩定。 median表示中位數; max當然就是表示最大值了。
Connect:        5 1642 1917.9   1332   33195	#網絡連結(Connect)
Processing:    75 1532 1506.3   1171   14254	#系統處理(Processing)
Waiting:       74 1494 1506.6   1102   14253	#等待(Waiting)
Total:        173 3174 2856.8   3099   35740	#Total是從整個請求所需要的時間的角度來統計的。這裡可以看到最慢的一個請求花費了35740ms,這個資料可以在下面的表中得到驗證。

Percentage of the requests served within a certain time (ms)
  50%   3099	#在這1000個請求中有50%在3099毫秒内完成
  66%   3607	#在這1000個請求中有66%在3607毫秒内完成
  75%   4137
  80%   5717
  90%   6731
  95%   8287
  98%  11306
  99%  12035
 100%  35740 (longest request)
           

繼續閱讀