壓力測試

[root@localhost ~]# /usr/local/apache/bin/ab -n1000 -c10 http://localhost/index.htmlThis is ApacheBench,Version2.3<$Revision:655654 $>Copyright1996AdamTwiss,ZeusTechnologyLtd, http://www.zeustech.net/Licensed to TheApacheSoftwareFoundation, http://www.apache.org/Benchmarking localhost (be patient)Completed100 requestsCompleted200 requestsCompleted300 requestsCompleted400 requestsCompleted500 requestsCompleted600 requestsCompleted700 requestsCompleted800 requestsCompleted900 requestsCompleted1000 requestsFinished1000 requests 
ServerSoftware:Apache/2.2.19ServerHostname:        localhostServerPort:80DocumentPath:/index.htmlDocumentLength:45 bytes 
ConcurrencyLevel:10Time taken for tests:0.454 secondsComplete requests:1000Failed requests:0Write errors:0Total transferred:322644 bytes
HTML transferred:45090 bytesRequests per second:2204.64[#/sec] (mean)Time per request:4.536[ms](mean)Time per request:0.454[ms](mean, across all concurrent requests)Transfer rate:694.64[Kbytes/sec] received 
ConnectionTimes(ms)
              min  mean[+/-sd] median   maxConnect:010.515Processing:135.6262Waiting:035.6262Total:145.6363Percentage of the requests served within a certain time (ms)50%366%475%480%490%695%1298%2699%33100%63(longest request)

 請注意咱們在啓動ab時,傳入3個命令行參數,它們正是表明了前面提到的前提條件:
-n1000 表示總請求數位1000
-c 表示併發用戶數爲10
http://localhost/index.html 表示這些請求的目標URL。
測試結果一目瞭然,咱們看到吞吐率顯示爲2204.64reqs/s。同時,在測試結果中還有一些其餘內容也值得咱們關注,主要包括:
Server Software
表示被測試的Web服務器軟件名稱,這裏是Apache/2.2.19,它來自於http響應數據的頭信息,因此若是是咱們本身編寫的Web服務器軟或者修改開源Web服務器軟件的源代碼,即可以隨意改寫這裏的名稱。
vi /usr/local/apache/conf/httpd.conf #隱藏具體版本信息
ServerSignature Off
ServerTokens Prodhtml

Server Hostname
表示請求的URL中的主機部分名稱,它來自於http請求數據的頭信息,這裏咱們請求的URL是http://localhost/index.html,因此主機名爲localhost,說明咱們的請求是從Web服務器端發起的。apache

Server Port
表示被測試的Web服務器軟件的監聽端口,爲了方便測試,咱們後面會對多個不一樣的Web服務器軟件使用不一樣的監聽端口。服務器

Document Path
表示請求的URL中根絕對路徑,它一樣來自於http請求數據的頭信息,經過它的後綴名,咱們通常能夠理解該請求的類型。併發

Document Length
表示http響應數據的正文長度。測試

Concurrency Level
表示併發用戶數,這是咱們設置的參數。spa

Time taken for tests
表示全部這些請求被處理完成花費的總時間。順便提一下,某些Apache版本如2.2.4附帶的ab,對於這一統計項存在一些計算上的bug,當總請求數較少時,其統計的總時間會沒法小於0.1s。.net

Complete requests
表示總請求數,這是咱們設置的相應參數。命令行

Failed requests
表示失敗的請求數,這裏的失敗是指請求的鏈接服務器、發送數據、接收數據等環節發生異常,以及無響應後超時的狀況。對於超時時間的設置能夠用ab的-t參數。
而若是接受到的http響應數據的頭信息中含有2xx之外的狀態碼,則會在測試結果顯示另外一個名爲「Non-2xx responses」的統計項,用於統計這部分請求數,這些請求並不算是失敗的請求。code

Total transferred
表示全部請求的響應數據長度總和,包括每一個http響應數據的頭信息和正文數據的長度。注意這裏不包括http請求數據的長度,因此Total
transferred表明了從Web服務器流向用戶PC的應用層數據總長度。經過使用ab的-v參數便可查看詳細的http頭信息。htm

HTML transferred
表示全部請求的響應數據中正文數據的總和,也就是減去了Total transferred中http響應數據中頭信息的長度。

Requests per second
這即是咱們重點關注的吞吐率,它等於:
Complete requests / Time taken for tests

Time per request
這即是前面提到的用戶平均請求等待時間,它等於:
Time taken for tests / (Complete requests /Concurrency Level)

Time per request?(across all concurrent requests)
這即是前面提到的服務器平均請求處理時間,它等於:
Time taken for tests / Complete requests

這正是吞吐率的倒數。同時,它也等於:
Time per request / Concurrency Level

Transfer rate
表示這些請求在單位時間內從服務器獲取的數據長度,它等於:
Total transferred / Time taken for tests
這個統計項能夠很好的說明服務器在處理能力達到限制時,其出口帶寬的需求量。
利用前面介紹的有關帶寬的知識,不難計算出結果。

Percentage of the requests served within a certain time(ms)
這部分數據用於描述每一個請求處理時間的分佈狀況,好比在以上測試結果中,80%請求的處理時間都不超過1ms,而99%的請求都不超過2ms。注意這裏的處理時間,是指前面的Time per request,即對於單個用戶而言,平均每一個請求處理的時間。

繼續壓力測試
下面,咱們再來進行一次壓力測試,此時併發用戶數爲100,其餘條件不變,測試結果以下所示:

[root@localhost ~]# /usr/local/apache/bin/ab -n1000 -c100 http://localhost/index.htmlThis is ApacheBench,Version2.3<$Revision:655654 $>Copyright1996AdamTwiss,ZeusTechnologyLtd, http://www.zeustech.net/Licensed to TheApacheSoftwareFoundation, http://www.apache.org/Benchmarking localhost (be patient)Completed100 requestsCompleted200 requestsCompleted300 requestsCompleted400 requestsCompleted500 requestsCompleted600 requestsCompleted700 requestsCompleted800 requestsCompleted900 requestsCompleted1000 requestsFinished1000 requests
ServerSoftware:Apache/2.2.19ServerHostname:        localhostServerPort:80DocumentPath:/index.htmlDocumentLength:45 bytes 
ConcurrencyLevel:100Time taken for tests:0.369 secondsComplete requests:1000Failed requests:0Write errors:0Total transferred:283648 bytes
HTML transferred:46080 bytesRequests per second:2711.45[#/sec] (mean)Time per request:36.881[ms](mean)Time per request:0.369[ms](mean, across all concurrent requests)Transfer rate:751.07[Kbytes/sec] received 
ConnectionTimes(ms)
              min  mean[+/-sd] median   maxConnect:0123.41219Processing:112318.917122Waiting:61918.313114Total:203517.130128Percentage of the requests served within a certain time (ms)50%3066%3275%3480%3590%5395%7598%9999%114100%128(longest request)

和前一次的測試結果相比,能夠看出,當併發用戶數據從原來的10變爲100後,吞吐率從原來的2204.64增加到了2711.45,服務器平均請求處理時間從原來的0.454ms降到了0.369ms,而用戶評價請求等待時間從原來的4.536ms增長到了36.881ms.可見,隨着併發用戶數的變化,吞吐率、用戶平均請求等待時間、服務器配件請求處理時間都發生了相應的變化。

相關文章
相關標籤/搜索