軟件壓力測試是一種基本的質量保證行為,它是每個重要軟件測試工作的一部分。軟件壓力測試的基本思路很簡單:不是在常規條件下運行手動或自動測試,而是在計算機數量較少或系統資源匱乏的條件下運行測試。通常要進行軟件壓力測試的資源包括內部內存、CPU 可用性、磁盤空間和網絡帶寬。
因此,軟件壓力測試一個非常重要的環節,Apache自帶了一個稱為ab的壓力測試小工具,全稱為ApacheBench,是專門用于HTTP Server的benchmark testing,可以同時模擬多個并發請求。
在這個例子的一開始,我執行了這樣一個命令ab -n 10 -c 10 http://www.google.com/。這個命令的意思是啟動ab,向www.google.com發送10個請求(-n 10) ,并每次發送10個請求(-c 10)——也就是說一次都發過去了。跟著下面的是ab輸出的測試報告。
D:/apahce/bin>ab.exe -n 10 -c 10 http://www.google.com/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.google.com (be patient).....done
Server Software: gws
Server Hostname: www.google.com
Server Port: 80
Document Path: /
Document Length: 4941 bytes
Concurrency Level: 10
Time taken for tests: 5.218750 seconds//**整個測試持續的時間**
Complete requests: 10//**完成的請求數量**
Failed requests: 9//**失敗的請求數量**
(Connect: 0, Length: 9, Exceptions: 0)
Write errors: 0
Total transferred: 52730 bytes**整個場景中的網絡傳輸量**
HTML transferred: 49540 bytes**整個場景中的HTML內容傳輸量**
Requests per second: 1.92 [#/sec] (mean) **大家最關心的指標之一,相當于LR中的每秒事務數,后面括號中的mean表示這是一個平均值**
Time per request: 5218.750 [ms] (mean) *大家最關心的指標之二,相當于LR中的平均事務響應時間,后面括號中的mean表示這是一個平均值**
Time per request: 521.875 [ms] (mean, across all concurrent requests)
Transfer rate: 9.77 [Kbytes/sec] received*平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導致響應時間延長的問題**
Connection Times (ms)
min mean[+/-sd] median max
Connect: 187 488 257.6 437 921
Processing: 312 1673 1204.4 1547 3985
Waiting: 296 1668 1206.3 1546 3984
Total: 593 2162 1432.6 1890 4906
下面的內容為整個場景中所有請求的響應情況。在場景中每個請求都有一個響應時間,其中50%的用戶響應時間小于**毫秒,60%的用戶響應時間小于**毫秒,最大的響應時間小于 **毫秒**
Percentage of the requests served within a certain time (ms)
50% 1890
66% 2406
75% 3093
80% 3984
90% 4906
95% 4906
98% 4906
99% 4906
100% 4906 (longest request)
格式:
./ab [options] [http://]hostname[:port]/path
參數:
-n requests Number of requests to perform //在測試會話中所執行的請求個數。默認時,僅執行一個請求
-c concurrency Number of multiple requests to make //一次產生的請求個數。默認是一次一個。
-t timelimit Seconds to max. wait for responses //測試所進行的最大秒數。其內部隱含值是-n 50000。它可以使對服務器的測試限制在一個固定的總時間以內。默認時,沒有時間限制。
-p postfile File containing data to POST //包含了需要POST的數據的文件.
-T content-type Content-type header for POSTing //POST數據所使用的Content-type頭信息。
-v verbosity How much troubleshooting info to print //設置顯示信息的詳細程度 - 4或更大值會顯示頭信息, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號并退出。
-w Print out results in HTML tables //以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表。
-i Use HEAD instead of GET // 執行HEAD請求,而不是GET。
-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 //
-C attribute Add cookie, eg. 'Apache=1234. (repeatable) //-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數可以重復。
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password. //
-P proxy-auth-username:password 對一個中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,并以base64編碼形式發送。無論服務器是否需要(即, 是否發送了401認證需求代碼),此字符串都會被發送。
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
新聞熱點
疑難解答