Apache 的 ab 壓測工具快速使用

  ab 是一個 httpd 自帶的很好用的壓力測試工具,它是 apache bench 命令的縮寫。ab 命令會建立多個併發訪問線程,模擬多個訪問者同時對某一 URL 地址進行訪問。能夠用來測試 apache 的負載壓力,也能夠用來測試 nginx、lighthttp、tomcat、IIS 等其它 Web 服務器的壓力負載性能。nginx

安裝

yum -y install httpd-tools

 查看是否安裝成功

ab -V

 help 查看 ab 參數詳細說明apache

ab --help

 正式壓測

ab -n 100 -c 20 http://www.baidu.com

  -n 表示 100 個請求,-c 模擬 20 併發,至關於20我的同時訪問後面的測試 URLtomcat

ab -t 60 -c 100 http://www.baidu.com

  在 60s 內發請求,一次 100 個請求bash

結果參數解釋

Completed 100 requests 
Completed 200 requests 
Completed 300 requests 
Completed 400 requests 
Completed 500 requests 
Completed 600 requests 
Completed 700 requests 
Completed 800 requests 
Finished 800 requests
Server Software:        Microsoft-HTTPAPI/2.0       表示被測試的Web服務器軟件名稱
Server Hostname:        192.168.0.10                表示請求的URL主機名
Server Port:               80                       表示被測試的Web服務器軟件的監聽端口
Document Path:             /                        表示請求的URL中的根絕對路徑,經過該文件的後綴名,咱們通常能夠了解該請求的類型
Document Length:        315 bytes                   表示HTTP響應數據的正文長度
Concurrency Level:        800                       表示併發用戶數,是咱們設置的參數之一
Time taken for tests:   0.914 seconds               全部這些請求處理完成所花費的時間
Complete requests:        800                       完成請求數
Failed requests:           0                        失敗請求數
Write errors:              0                
Non-2xx responses:        800 
Total transferred:        393600 bytes              網絡總傳輸量
HTML transferred:         252000 bytes              HTML內容傳輸量 
Requests per second:     875.22 [#/sec] (mean)      吞吐量-每秒請求數
Time per request:        914.052 [ms] (mean)        服務器收到請求,響應頁面要花費的時間
Time per request:       1.143 [ms] (mean, across all concurrent requests) 併發的每一個請求平均消耗時間 
Transfer rate:          420.52 [Kbytes/sec] received 平均每秒網絡上的流量,能夠幫助排除是否存在網絡流量過大致使響應時間延長的問題

網絡上消耗的時間的分解:

Connection Times (ms)  min  mean[+/-sd] median   max 
Connect:        0       1       0.5      1       3 
Processing:    245     534     125.2    570     682 
Waiting:       11      386     189.1    409     669 
Total:         246     535     125.0    571     684

整個場景中全部請求的響應狀況。在場景中每一個請求都有一個響應時間服務器

其中 50% 的用戶響應時間小於 571 毫秒網絡

80% 的用戶響應時間小於 652 毫秒併發

最大的響應時間小於 684 毫秒工具

Percentage of the requests served within a certain time (ms) 
  50%    571 
  66%    627 
  75%    646 
  80%    652 
  90%    666 
  95%    677 
  98%    681 
  99%    682 
  100%   684 (longest request)
相關文章
相關標籤/搜索