1. 程式人生 > >ab簡單的叢集壓力測試驗證

ab簡單的叢集壓力測試驗證

Apache附帶的ab工具(本機使用的PHP環境是WAMP整合環境,ab工具位於D:\wamp\bin\apache\Apache2.2.21\bin)非常容易使用,ab可以直接在Web伺服器本地發起測試請求,這至關重要,因為有些時候我們需要測試的僅僅是伺服器的處理效能,並不想摻雜著網路傳輸時間的影響。ab進行一切測試的本質都是基於HTTP的,所以可以說ab對於Web伺服器軟體的黑盒效能測試,獲得的一切資料和計算結果,都是可以通過HTTP來解釋的。

測試本機是否正確安裝ab工具,在power shell想將當前目錄定位到bin,輸入  .\ab –V 命令,如果安裝正確,則會將其版本資訊打印出來。

1 2 3 4 PS D:\wamp\bin\apache\Apache2.2.21\bin> .\ab -V This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech Licensed to The Apache Software Foundation, <a href=>http://www.apache.org/</a>

好了,一切就緒,下面提供一個壓力測試的例項:

輸入命令 PS D:\wamp\bin\apache\Apache2.2.21\bin> .\ab -n1000 -c10 http://localhost/index.php

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests 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:        Apache/2.2.21 Server Hostname:        localhost Server Port:            80 Document Path:          /index.php Document Length:        211 bytes Concurrency Level:      10 Time taken for tests:   0.496 seconds Complete requests:      1000 Failed requests:        0 Write errors:           0 Non-2xx responses:      1000 Total transferred:      400000 bytes HTML transferred:       211000 bytes Requests per second:    2015.93 [#/sec] (mean) Time per request:       4.960 [ms] (mean) Time per request:       0.496 [ms] (mean, across all concurrent requests) Transfer rate:          787.47 [Kbytes/sec] received Connection Times (ms) min  mean[+/-sd] median   max Connect:        0    0   0.4      0       1 Processing:     2    5   1.1      4      12 Waiting:        2    4   1.1      4      12 Total:          2    5   1.1      5      12 Percentage of the requests served within a certain time (ms) 50%      5 66%      5 75%      5 80%      6 90%      6 95%      7 98%      8 99%      9 100%     12 (longest request)

下面開始解析這條命令語句:啟動ab,並出入三個引數(PS D:\wamp\bin\apache\Apache2.2.21\bin> .\ab -n1000 -c10http://localhost/index.php 

-n1000 表示請求總數為1000

-c10 表示併發使用者數為10

測試結果也一目瞭然,測試出的吞吐率為:Requests per second: 2015.93 [#/sec] (mean)  初次之外還有其他一些資訊。

Server Software 表示被測試的Web伺服器軟體名稱

Server Hostname 表示請求的URL主機名

Server Port 表示被測試的Web伺服器軟體的監聽埠

Document Path 表示請求的URL中的根絕對路徑,通過該檔案的字尾名,我們一般可以瞭解該請求的型別

Document Length 表示HTTP響應資料的正文長度

Concurrency Level 表示併發使用者數,這是我們設定的引數之一

Time taken for tests 表示所有這些請求被處理完成所花費的總時間

Complete requests 表示總請求數量,這是我們設定的引數之一

Failed requests 表示失敗的請求數量,這裡的失敗是指請求在連線伺服器、傳送資料等環節發生異常,以及無響應後超時的情況。如果接收到的HTTP響應資料的頭資訊中含有2XX以外的狀態碼,則會在測試結果中顯示另一個名為       “Non-2xx responses”的統計項,用於統計這部分請求數,這些請求並不算在失敗的請求中。

Total transferred 表示所有請求的響應資料長度總和,包括每個HTTP響應資料的頭資訊和正文資料的長度。注意這裡不包括HTTP請求資料的長度,僅僅為web伺服器流向使用者PC的應用層資料總長度。

HTML transferred 表示所有請求的響應資料中正文資料的總和,也就是減去了Total transferred中HTTP響應資料中的頭資訊的長度。

Requests per second 吞吐率,計算公式:Complete requests / Time taken for tests

Time per request 使用者平均請求等待時間,計算公式:Time token for tests/(Complete requests/Concurrency Level)

<