軟件壓力測(cè)試是一種基本的質(zhì)量保證行為,它是每個(gè)重要軟件測(cè)試工作的一部分。軟件壓力測(cè)試的基本思路很簡(jiǎn)單:不是在常規(guī)條件下運(yùn)行手動(dòng)或自動(dòng)測(cè)試,而是在計(jì)算機(jī)數(shù)量較少或系統(tǒng)資源匱乏的條件下運(yùn)行測(cè)試。通常要進(jìn)行軟件壓力測(cè)試的資源包括內(nèi)部?jī)?nèi)存、CPU 可用性、磁盤空間和網(wǎng)絡(luò)帶寬。
因此,軟件壓力測(cè)試一個(gè)非常重要的環(huán)節(jié),Apache自帶了一個(gè)稱為ab的壓力測(cè)試小工具,全稱為ApacheBench,是專門用于HTTP Server的benchmark testing,可以同時(shí)模擬多個(gè)并發(fā)請(qǐng)求。
在這個(gè)例子的一開始,我執(zhí)行了這樣一個(gè)命令ab -n 10 -c 10 http://www.google.com/。這個(gè)命令的意思是啟動(dòng)ab,向www.google.com發(fā)送10個(gè)請(qǐng)求(-n 10) ,并每次發(fā)送10個(gè)請(qǐng)求(-c 10)——也就是說一次都發(fā)過去了。跟著下面的是ab輸出的測(cè)試報(bào)告。
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//**整個(gè)測(cè)試持續(xù)的時(shí)間**
Complete requests: 10//**完成的請(qǐng)求數(shù)量**
Failed requests: 9//**失敗的請(qǐng)求數(shù)量**
(Connect: 0, Length: 9, Exceptions: 0)
Write errors: 0
Total transferred: 52730 bytes**整個(gè)場(chǎng)景中的網(wǎng)絡(luò)傳輸量**
HTML transferred: 49540 bytes**整個(gè)場(chǎng)景中的HTML內(nèi)容傳輸量**
Requests per second: 1.92 [#/sec] (mean) **大家最關(guān)心的指標(biāo)之一,相當(dāng)于LR中的每秒事務(wù)數(shù),后面括號(hào)中的mean表示這是一個(gè)平均值**
Time per request: 5218.750 [ms] (mean) *大家最關(guān)心的指標(biāo)之二,相當(dāng)于LR中的平均事務(wù)響應(yīng)時(shí)間,后面括號(hào)中的mean表示這是一個(gè)平均值**
Time per request: 521.875 [ms] (mean, across all concurrent requests)
Transfer rate: 9.77 [Kbytes/sec] received*平均每秒網(wǎng)絡(luò)上的流量,可以幫助排除是否存在網(wǎng)絡(luò)流量過大導(dǎo)致響應(yīng)時(shí)間延長(zhǎng)的問題**
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
下面的內(nèi)容為整個(gè)場(chǎng)景中所有請(qǐng)求的響應(yīng)情況。在場(chǎng)景中每個(gè)請(qǐng)求都有一個(gè)響應(yīng)時(shí)間,其中50%的用戶響應(yīng)時(shí)間小于**毫秒,60%的用戶響應(yīng)時(shí)間小于**毫秒,最大的響應(yīng)時(shí)間小于 **毫秒**
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
參數(shù):
-n requests Number of requests to perform //在測(cè)試會(huì)話中所執(zhí)行的請(qǐng)求個(gè)數(shù)。默認(rèn)時(shí),僅執(zhí)行一個(gè)請(qǐng)求
-c concurrency Number of multiple requests to make //一次產(chǎn)生的請(qǐng)求個(gè)數(shù)。默認(rèn)是一次一個(gè)。
-t timelimit Seconds to max. wait for responses //測(cè)試所進(jìn)行的最大秒數(shù)。其內(nèi)部隱含值是-n 50000。它可以使對(duì)服務(wù)器的測(cè)試限制在一個(gè)固定的總時(shí)間以內(nèi)。默認(rèn)時(shí),沒有時(shí)間限制。
-p postfile File containing data to POST //包含了需要POST的數(shù)據(jù)的文件.
-T content-type Content-type header for POSTing //POST數(shù)據(jù)所使用的Content-type頭信息。
-v verbosity How much troubleshooting info to print //設(shè)置顯示信息的詳細(xì)程度 - 4或更大值會(huì)顯示頭信息, 3或更大值可以顯示響應(yīng)代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號(hào)并退出。
-w Print out results in HTML tables //以HTML表的格式輸出結(jié)果。默認(rèn)時(shí),它是白色背景的兩列寬度的一張表。
-i Use HEAD instead of GET // 執(zhí)行HEAD請(qǐng)求,而不是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 對(duì)請(qǐng)求附加一個(gè)Cookie:行。 其典型形式是name=value的一個(gè)參數(shù)對(duì)。此參數(shù)可以重復(fù)。
-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 對(duì)一個(gè)中轉(zhuǎn)代理提供BASIC認(rèn)證信任。用戶名和密碼由一個(gè):隔開,并以base64編碼形式發(fā)送。無論服務(wù)器是否需要(即, 是否發(fā)送了401認(rèn)證需求代碼),此字符串都會(huì)被發(fā)送。
-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)
新聞熱點(diǎn)
疑難解答
圖片精選