2007年3月23日 星期五

apache內建的壓力測試軟體

轉貼自http://www.twbb.org/viewthread.php?tid=8158
APACHE專用的壓力測試工具


在阿帕契服務器的套件中,有一個叫做 ab (ApacheBench) 的工具。ApacheBench 主要是用來測試阿帕契服務器執行效率用的,我們就以 ApacheBench 做為 CGI vs. FastCGI 的評比工具。

ApacheBench 可以針對某個特定的 URL 仿真出連續的聯機請求,同時還可以仿真出同時間點數個相同的聯機請求,因此利用 ApacheBench 可幫助我們在網站開發期間仿真實際上線可能的情況,利用仿真出來的數據做為調整服務器設定或程序的依據。 ApacheBench 的用法如下:

Usage: /usr/local/apache/bin/ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-p postfile File containg data to POST
-T content-type Content-type header for POSTing
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-V Print version number and exit
-k Use HTTP KeepAlive feature
-h Display usage information (this message)

假設我們要對 echo.fcg 做測試,仿真 1000 次的聯機請求,而且同一時間有 20 個並行的 (concurrent) 聯機請求的情況,只要在命令列模式下執行

$ ab -n 1000 -c 20 http://localhost/fcgi-bin/echo.fcg
稍等一會,ApacheBench 會把結果秀出來,

This is ApacheBench, Version 1.3
Copyright © 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright © 1998-1999 The Apache Group, http://www.apache.org/

Benchmarking localhost (be patient)... Server Software: Apache/1.3.6
Server Hostname: localhost
Server Port: 80
Document Path: /fcgi-bin/echo.fcg
Document Length: 995 bytes
Concurrency Level: 20
Time taken for tests: 6.859 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 1142000 bytes
HTML transferred: 995000 bytes
Requests per second: 145.79
Transfer rate: 166.50 kb/s received

Connnection Times (ms)
min avg max

Connect: 0 4 61
Processing: 62 128 771
Total: 62 132 832

以上結果指出,在同時間 20 個聯機請求 (Concurrency Level) 的情況下,完成 1000 次的聯機請求,共花了 6.859 秒 (Time taken for tests),因此這個程序每秒平均可以處理 (Requests per second) 145.79 個聯機請求。
在接下來的評比測試中,我們就以每秒可以處理的聯機請求數目來做為效能評比的依據。

=====================================================================


在linux rpm安裝的話ab是在/usr/bin/ab
如果是在win32的話裝appserv路徑大約是這樣C:\AppServ\Apache2.2\bin\ab.exe

沒有留言: