查看完整版本: Apache 專用的壓力測試工具 -- ab


adj 2007-11-29 21:56

Apache 專用的壓力測試工具 -- ab

在阿帕契服務器的套件中,有一個叫做 ab (ApacheBench) 的工具。ApacheBench 主要是用來測試阿帕契服務器執行效率用的,我們就以 ApacheBench 做為 CGI vs. FastCGI 的評比工具。 <br><br>ApacheBench 可以針對某個特定的 URL 仿真出連續的聯機請求,同時還可以仿真出同時間點數個相同的聯機請求,因此利用 ApacheBench 可幫助我們在網站開發期間仿真實際上線可能的情況,利用仿真出來的數據做為調整服務器設定或程序的依據。 ApacheBench 的用法如下: <br><br>Usage: /usr/local/apache/bin/ab [options] [http://]hostname[:port]/path <br>Options are: <br>-n requests Number of requests to perform <br>-c concurrency Number of multiple requests to make <br>-t timelimit Seconds to max. wait for responses <br>-p postfile File containg data to POST <br>-T content-type Content-type header for POSTing <br>-v verbosity How much troubleshooting info to print <br>-w Print out results in HTML tables <br>-x attributes String to insert as table attributes <br>-y attributes String to insert as tr attributes <br>-z attributes String to insert as td or th attributes <br>-V Print version number and exit <br>-k Use HTTP KeepAlive feature <br>-h Display usage information (this message) <br><br><p><strong>而我經常使用的參數摘要如下:</strong></p>
<p><br></p><p>1. 同時 20 個連線,連續點擊 1000 次 ( 每個 Request 執行完畢後都會自動斷線,然後再重新連線 )</p><p>[quote]</p><p>ab -n 1000 -c 20 http://www.example.com/index.php<br></p><p>[/quote]</p><p><br></p><p>2. 同時 20 個連線,連續點擊 1000 次,並且使用 Keep-Alive 方式連線</p><p>(當 Web Server 有支援 Keep-Alive 功能時 ApacheBench 會在同一個連線下連續點擊該網頁)<br>[quote]<br>ab -n 1000 -c 20 -k http://www.example.com/index.php<br>[/quote]<br></p><p><br></p><p>3. 將測試的效能原始資料匯出成 CSV 檔<br>[quote]<br>ab -e output.csv -n 1000 -c 20 http://www.example.com/index.php<br></p>[/quote]<br><br>如何有效的檢視結果<br><br>壓力測試的核心在於如何分析結果,底下我用一個測試的結果說明每個欄位所代表的意義。如果你只要看重點的話,可以看 Failed requests、Requests per second、與 Time per request 這三個參數也就差不多夠了。<br>其中的 Failed requests 的數量太高的話,很有可能代表你的 Web Application 的穩定度不夠,而導致使用大量要求時無法回應需求 。<br>而 Request per second 代表你每表可送出的回應數有多少,代表你 Web Application 的承載量有多少(在不考慮頻寬限制的情況下)。<br><br>[quote]<br>Server Software:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apache/2.2.25<br>Server Hostname:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; www.adj.idv.tw<br>Server Port:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 80<br><br>Document Path:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /<br>Document Length:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 bytes<br><br>Concurrency Level:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20<br>Time taken for tests:&nbsp;&nbsp; 6.585 seconds<br>Complete requests:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1000<br>Failed requests:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br>Write errors:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br>Non-2xx responses:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1000<br>Total transferred:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 277000 bytes<br>HTML transferred:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 bytes<br>Requests per second:&nbsp;&nbsp;&nbsp; 151.86 [#/sec] (mean)<br>Time per request:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 131.702 [ms] (mean)<br>Time per request:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6.585 [ms] (mean, across all concurrent requests)<br>Transfer rate:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 41.08 [Kbytes/sec] received<br><br>Connection Times (ms)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; min&nbsp; mean[+/-sd] median&nbsp;&nbsp; max<br>Connect:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 59&nbsp;&nbsp; 60&nbsp;&nbsp; 0.5&nbsp;&nbsp;&nbsp;&nbsp; 60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 66<br>Processing:&nbsp;&nbsp;&nbsp; 67&nbsp;&nbsp; 70&nbsp; 13.6&nbsp;&nbsp;&nbsp;&nbsp; 69&nbsp;&nbsp;&nbsp;&nbsp; 445<br>Waiting:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 67&nbsp;&nbsp; 70&nbsp; 13.6&nbsp;&nbsp;&nbsp;&nbsp; 69&nbsp;&nbsp;&nbsp;&nbsp; 445<br>Total:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 126&nbsp; 131&nbsp; 13.7&nbsp;&nbsp;&nbsp; 129&nbsp;&nbsp;&nbsp;&nbsp; 504<br><br>Percentage of the requests served within a certain time (ms)<br>&nbsp; 50%&nbsp;&nbsp;&nbsp; 129<br>&nbsp; 66%&nbsp;&nbsp;&nbsp; 130<br>&nbsp; 75%&nbsp;&nbsp;&nbsp; 130<br>&nbsp; 80%&nbsp;&nbsp;&nbsp; 131<br>&nbsp; 90%&nbsp;&nbsp;&nbsp; 132<br>&nbsp; 95%&nbsp;&nbsp;&nbsp; 133<br>&nbsp; 98%&nbsp;&nbsp;&nbsp; 140<br>&nbsp; 99%&nbsp;&nbsp;&nbsp; 151<br>&nbsp;100%&nbsp;&nbsp;&nbsp; 504 (longest request)<br>[/quote]<br><br>如上表顯示的結果來說明,我一個欄位一個欄位的講解如下:<br><br>&nbsp;&nbsp;&nbsp; Server Software:&nbsp;&nbsp;&nbsp; Web主機的作業系統與版本(若Web主機設定關閉此資訊則無)<br>&nbsp;&nbsp;&nbsp; Server Hostname:&nbsp; Web主機的IP位址(Hostname)<br>&nbsp;&nbsp;&nbsp; Server Port:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Web主機的連接埠(Port)<br>&nbsp;&nbsp;&nbsp; Document Path:&nbsp;&nbsp;&nbsp;&nbsp; 測試網址的路徑部分<br>&nbsp;&nbsp;&nbsp; Document Length: 測試網頁回應的網頁大小<br>&nbsp;&nbsp;&nbsp; Concurrency Level: 同時進行壓力測試的人數<br>&nbsp;&nbsp;&nbsp; Time taken for tests: 本次壓力測試所花費的總秒數<br>&nbsp;&nbsp;&nbsp; Complete requests: 完成的要求數(Requests)<br>&nbsp;&nbsp;&nbsp; Failed requests:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 失敗的要求數(Requests)<br>&nbsp;&nbsp;&nbsp; Write errors:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 寫入失敗的數量<br>&nbsp;&nbsp;&nbsp; Total transferred:&nbsp;&nbsp; 本次壓力測試的總數據傳輸量(包括 HTTP Header 的資料也計算在內)<br>&nbsp;&nbsp;&nbsp; HTML transferred:&nbsp; 本次壓力測試的總數據傳輸量(僅計算回傳的 HTML 的資料)<br>&nbsp;&nbsp;&nbsp; Requests per second: 平均每秒可回應多少要求<br>&nbsp;&nbsp;&nbsp; Time per request:&nbsp; 平均每個要求所花費的時間(單位: 豪秒)<br>&nbsp;&nbsp;&nbsp; Time per request:&nbsp; 平均每個要求所花費的時間,跨所有同時連線數的平均值(單位: 豪秒)<br>&nbsp;&nbsp;&nbsp; Transfer rate:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 從 ab 到 Web Server 之間的網路傳輸速度<br><br>參考文章:<br>http://blog.miniasp.com/post/2008/06/Using-ApacheBench-ab-to-to-Web-stress-test.aspx<br>
頁: [1]
查看完整版本: Apache 專用的壓力測試工具 -- ab