Siege(英文意思是圍攻)是一個(gè)壓力測(cè)試和評(píng)測(cè)工具,設(shè)計(jì)用于WEB開發(fā)這評(píng)估應(yīng)用在壓力下的承受能力:可以根據(jù)配置對(duì)一個(gè)WEB站點(diǎn)進(jìn)行多用戶的并發(fā)訪問,記錄每個(gè)用戶所有請(qǐng)求過程的相應(yīng)時(shí)間,并在一定數(shù)量的并發(fā)訪問下重復(fù)進(jìn)行。
Siege
說明
ab的主要弱點(diǎn)在于它不能讓你模擬一個(gè)更加真實(shí)的請(qǐng)求分布——例如你想通過設(shè)置一個(gè)請(qǐng)求的列表來在這些列表之間來回測(cè)試,而siege就可以。
安裝
siege需要自己從http://www.joedog.org/上自己下載,然后編譯:
./configure --prefix=/usr/local/siege --mandir=/usr/local/man
make
# 轉(zhuǎn)到超級(jí)用戶
make install
注意在configure的時(shí)候,一定要設(shè)置mandir參數(shù),否則當(dāng)你通過 man siege查看siege幫助的時(shí)候會(huì)看不到他的manual.
安裝完成后,運(yùn)行bin中的siege_config命令來創(chuàng)建.siege文件之后,你可以通過
./siege -C
命令來查看當(dāng)前配置
最簡(jiǎn)單的使用命令:
./siege http://localhost/
#用來測(cè)試本地主頁
參數(shù)介紹
- -cNUM
設(shè)置并發(fā)的用戶(連接)數(shù)量. 默認(rèn)的連接數(shù)量可以到~/.siegerc中查看,指令為concurrent = x。比如-c10,設(shè)置并發(fā)10個(gè)連接
- -rNUM
(repetitions),重復(fù)數(shù)量,即每個(gè)連接發(fā)出的請(qǐng)求數(shù)量,設(shè)置這個(gè)的話,就不需要設(shè)置-t了。對(duì)應(yīng).siegerc配置文件中的reps = x指令
- -tNUM
(time),持續(xù)時(shí)間,即測(cè)試持續(xù)時(shí)間,在NUM時(shí)間后結(jié)束,單位默認(rèn)為分,比如-t10,那么測(cè)試時(shí)間為10分鐘,-t10s,則測(cè)試時(shí)間為10秒鐘。對(duì)應(yīng).siegerc中的指令為time = x指令
- -b
(benchmark),基準(zhǔn)測(cè)試,如果設(shè)置這個(gè)參數(shù)的話,那么delay時(shí)間為0。man siege中有一句話這樣說:
it's not recommanded that you use this option while load testing.
說明基準(zhǔn)測(cè)試和load testing 是完全不同的,至于有什么不同,可以閱讀BenchMarkingVSLoadTestingVSPerformance.
- -f url.txt
(file),這是文件。對(duì)應(yīng).siegerc配置文件中的file = x指令
- 其他比較關(guān)注的測(cè)試方法,比如我想使用Keep-Alive方式進(jìn)行測(cè)試,可以在.siegerc配置文件中進(jìn)行修改,將connect = close改為 connect = keep-alive
- 另外您還可以通過-H HEADER參數(shù)來設(shè)置請(qǐng)求header。
結(jié)果分析
待續(xù)...
最早使用的壓力測(cè)試工具是apache的ab(apache benchmark),apache ab做重復(fù)壓力測(cè)試不錯(cuò),但是每次只能測(cè)試一個(gè)鏈接,如何測(cè)試一組鏈接(比如從日志中導(dǎo)出的1個(gè)小時(shí)的日志,做真實(shí)壓力測(cè)試),后來找到了這個(gè):
Siege是一個(gè)壓力測(cè)試和評(píng)測(cè)工具,設(shè)計(jì)用于WEB開發(fā)這評(píng)估應(yīng)用在壓力下的承受能力:可以根據(jù)配置對(duì)一個(gè)WEB站點(diǎn)進(jìn)行多用戶的并發(fā)訪問,記錄每個(gè)用戶所有請(qǐng)求過程的相應(yīng)時(shí)間,并在一定數(shù)量的并發(fā)訪問下重復(fù)進(jìn)行。
SIEGE is an http regressive testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a webserver with a configurable number of concurrent simulated users. Those users place the webserver "under siege." The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test.
下載/安裝
Siege時(shí)一個(gè)開放源代碼項(xiàng)目:http://www.joedog.org/siege/
下載:
wget ftp://sid.joedog.org/pub/siege/siege-latest.tar.gz
安裝:
%./configure ; make
#make install
siege包含了一組壓力測(cè)試工具:
SIEGE (1) Siege是一個(gè)HTTP壓力測(cè)試和評(píng)測(cè)工具.
使用樣例:
任務(wù)列表:www.chedong.com.url文件
http://www.chedong.com/tech/
http://www.chedong.com/tech/acdsee.html
http://www.chedong.com/tech/ant.html
http://www.chedong.com/tech/apache_install.html
http://www.chedong.com/tech/awstats.html
http://www.chedong.com/tech/cache.html
http://www.chedong.com/tech/click.html
http://www.chedong.com/tech/cms.html
http://www.chedong.com/tech/compress.html
http://www.chedong.com/tech/cvs_card.html
http://www.chedong.com/tech/default.html
http://www.chedong.com/tech/dev.html
http://www.chedong.com/tech/gnu.html
....
siege -c 20 -r 2 -f www.chedong.com.url
參數(shù)說明:
-c 20 并發(fā)20個(gè)用戶
-r 2 重復(fù)循環(huán)2次
-f www.chedong.com.url 任務(wù)列表:URL列表
輸出樣例:
** Siege 2.59
** Preparing 20 concurrent users for battle. 這次“戰(zhàn)斗”準(zhǔn)備了20個(gè)并發(fā)用戶
The server is now under siege.. done. 服務(wù)在“圍攻”測(cè)試中:
Transactions: 40 hits 完成40次處理
Availability: 100.00 % 成功率
Elapsed time: 7.67 secs 總共用時(shí)
Data transferred: 877340 bytes 共數(shù)據(jù)傳輸:877340字節(jié)
Response time: 1.65 secs 相應(yīng)用時(shí)1.65秒:顯示網(wǎng)絡(luò)連接的速度
Transaction rate: 5.22 trans/sec 平均每秒完成5.22次處理:表示服務(wù)器后臺(tái)處理的速度
Throughput: 114385.92 bytes/sec 平均每秒傳送數(shù)據(jù):114385.92字節(jié)
Concurrency: 8.59 最高并發(fā)數(shù) 8.59
Successful transactions: 40 成功處理次數(shù)
Failed transactions: 0 失敗處理次數(shù)
注意:由于速度很快,可能會(huì)達(dá)不到并發(fā)速度很高就已經(jīng)完成。Response time顯示的是測(cè)試機(jī)器和被測(cè)試服務(wù)器之間網(wǎng)絡(luò)鏈接狀況。Transaction rate則表示服務(wù)器端任務(wù)處理的完成速度。
輔助工具:
增量壓力測(cè)試:
為了方便增量壓力測(cè)試,siege還包含了一些輔助工具:
bombardment (1)
是一個(gè)輔助工具:用于按照增量用戶壓力測(cè)試:
使用樣例:
bombardment urlfile.txt 5 3 4 1
初始化URL列表:urlfile.txt
初始化為:5個(gè)用戶
每次增加:3個(gè)用戶
運(yùn)行:4次
每個(gè)客戶端之間的延遲為:1秒
輸出成CSV格式:
siege2csv.pl (1)
siege2csv.pl將bombardment的輸出變成CSV格式:
Time Data Transferred Response Time Transaction Rate Throughput Concurrency Code 200 (note that this is horribly broken.)
242 60.22 603064 0.02 4.02 10014.35 0.08
605 59.98 1507660 0.01 10.09 25136.05 0.12
938 59.98 2337496 0.02 15.64 38971.26 0.26
1157 60 2883244 0.04 19.28 48054.07 0.78
參考:
開源測(cè)試工具:http://www.opensourcetesting.org/performance.php
[technorati relative tag]
[相關(guān)內(nèi)容]
由 tristones 發(fā)表于 2004年02月18日下午02時(shí)53分
留言
SIEGE測(cè)試于目標(biāo)網(wǎng)站的網(wǎng)頁動(dòng)態(tài)靜態(tài)沒有關(guān)系,只要任務(wù)列表是動(dòng)態(tài)網(wǎng)頁即可。即使是需要認(rèn)證的,也可以通過預(yù)先設(shè)置POST HEADER等方式模擬登錄。
done.
Transactions: 455 hits
Availability: 75.83 %
Elapsed time: 85.45 secs
Data transferred: 4097.30 MB
Response time: 11.32 secs
Transaction rate: 5.32 trans/sec
Throughput: 47.95 MB/sec
Concurrency: 60.30
Successful transactions: 455
Failed transactions: 145
Longest transaction: 53.61
Shortest transaction: 0.80
FILE: /usr/local/siege/var/siege.log
You can disable this annoying message by editing
the .siegerc file in your home directory; change
the directive 'show-logfile' to false.
[root@localhost bin]# ./siege -c 300 -r 2 -f /work/siege/siege.txt;
cat /usr/local/siege/var/siege.log
Date & Time, Trans, Elap Time, Data Trans, Resp Time, Trans Rate, Throughput, Concurrent, OKAY, Failed
2009-06-02 13:33:21, 455, 85.45, 4097, 11.32, 5.32, 47.95, 60.30, 455, 145
done.
Transactions: 192 hits
Availability: 96.00 %
Elapsed time: 78.64 secs
Data transferred: 0.09 MB
Response time: 5.13 secs
Transaction rate: 2.44 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 12.53
Successful transactions: 192
Failed transactions: 8
Longest transaction: 51.85
Shortest transaction: 1.14
FILE: /usr/local/siege/var/siege.log
You can disable this annoying message by editing
the .siegerc file in your home directory; change
the directive 'show-logfile' to false.
[root@localhost bin]# ./siege -c 100 -r 2 -f /work/siege/url.txt;
http://211.139.163.252/lsp/leService.do POST < /work/siege/data.txt
<?xml version="1.0" encoding="GBK"?><!DOCTYPE svc_init SYSTEM "MLP_SVC_INIT_320.DTD"><svc_init ver="3.2.0"><hdr ver="3.2.0"><client><id>1001</id><pwd>1001</pwd></client></hdr><slir ver="2.0.0" res_type="SYNC"><msids><msid>8613501502020</msid><msid>8613602887904</msid></msids><loc_type type="CURRENT_OR_LAST" /><prio type="NORMAL" /><req_result type="AREA_CODE" /></slir></svc_init>
一、http_load
程序非常小,解壓后也不到100K
http_load以并行復(fù)用的方式運(yùn)行,用以測(cè)試web服務(wù)器的吞吐量與負(fù)載。但是它不同于大多數(shù)壓力測(cè)試工
具,它可以以一個(gè)單一的進(jìn)程運(yùn)行,一般不會(huì)把客戶機(jī)搞死。還可以測(cè)試HTTPS類的網(wǎng)站請(qǐng)求。
下載地址:http://soft.vpser.net/test/http_load/http_load-12mar2006.tar.gz
安裝很簡(jiǎn)單
#tar zxvf http_load-12mar2006.tar.gz
#cd http_load-12mar2006
#make && make install
命令格式:http_load -p 并發(fā)訪問進(jìn)程數(shù) -s 訪問時(shí)間 需要訪問的URL文件
參數(shù)其實(shí)可以自由組合,參數(shù)之間的選擇并沒有什么限制。比如你寫成http_load -parallel 5 -seconds
300 urls.txt也是可以的。我們把參數(shù)給大家簡(jiǎn)單說明一下。
-parallel 簡(jiǎn)寫-p :含義是并發(fā)的用戶進(jìn)程數(shù)。
-fetches 簡(jiǎn)寫-f :含義是總計(jì)的訪問次數(shù)
-rate 簡(jiǎn)寫-p :含義是每秒的訪問頻率
-seconds簡(jiǎn)寫-s :含義是總計(jì)的訪問時(shí)間
準(zhǔn)備URL文件:urllist.txt,文件格式是每行一個(gè)URL,URL最好超過50-100個(gè)測(cè)試效果比較好.文件格式
如下:
http://www.vpser.net/uncategorized/choose-vps.html
http://www.vpser.net/vps-cp/hypervm-tutorial.html
http://www.vpser.net/coupons/diavps-april-coupons.html
http://www.vpser.net/security/vps-backup-web-mysql.html
例如:
http_load -p 30 -s 60 urllist.txt
參數(shù)了解了,我們來看運(yùn)行一條命令來看看它的返回結(jié)果
命令:% ./http_load -rate 5 -seconds 10 urls說明執(zhí)行了一個(gè)持續(xù)時(shí)間10秒的測(cè)試,每秒的頻率為5。
49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds5916 mean bytes/connection4.89274
fetches/sec, 28945.5 bytes/secmsecs/connect: 28.8932 mean, 44.243 max, 24.488 minmsecs/first
-response: 63.5362 mean, 81.624 max, 57.803 minHTTP response codes: code 200 — 49
結(jié)果分析:
1.49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
說明在上面的測(cè)試中運(yùn)行了49個(gè)請(qǐng)求,最大的并發(fā)進(jìn)程數(shù)是2,總計(jì)傳輸?shù)臄?shù)據(jù)是289884bytes,運(yùn)行的時(shí)間是10.0148秒
2.5916 mean bytes/connection說明每一連接平均傳輸?shù)臄?shù)據(jù)量289884/49=5916
3.4.89274 fetches/sec, 28945.5 bytes/sec
說明每秒的響應(yīng)請(qǐng)求為4.89274,每秒傳遞的數(shù)據(jù)為28945.5 bytes/sec
4.msecs/connect: 28.8932 mean, 44.243 max, 24.488 min說明每連接的平均響應(yīng)時(shí)間是28.8932 msecs
,最大的響應(yīng)時(shí)間44.243 msecs,最小的響應(yīng)時(shí)間24.488 msecs
5.msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
6、HTTP response codes: code 200 — 49 說明打開響應(yīng)頁面的類型,如果403的類型過多,那可能
要注意是否系統(tǒng)遇到了瓶頸。
特殊說明:
測(cè)試結(jié)果中主要的指標(biāo)是 fetches/sec、msecs/connect 這個(gè)選項(xiàng),即服務(wù)器每秒能夠響應(yīng)的查詢次數(shù),
用這個(gè)指標(biāo)來衡量性能。似乎比 apache的ab準(zhǔn)確率要高一些,也更有說服力一些。
Qpt-每秒響應(yīng)用戶數(shù)和response time,每連接響應(yīng)用戶時(shí)間。
測(cè)試的結(jié)果主要也是看這兩個(gè)值。當(dāng)然僅有這兩個(gè)指標(biāo)并不能完成對(duì)性能的分析,我們還需要對(duì)服務(wù)器的
cpu、men進(jìn)行分析,才能得出結(jié)論
二、webbench
webbench是Linux下的一個(gè)網(wǎng)站壓力測(cè)試工具,最多可以模擬3萬個(gè)并發(fā)連接去測(cè)試網(wǎng)站的負(fù)載能力。下載地址可以到google搜,我這里給出一個(gè)
下載地址:http://soft.vpser.net/test/webbench/webbench-1.5.tar.gz
這個(gè)程序更小,解壓后不到50K,呵呵
安裝非常簡(jiǎn)單
#tar zxvf webbench-1.5.tar.gz
#cd webbench-1.5
#make && make install
會(huì)在當(dāng)前目錄生成webbench可執(zhí)行文件,直接可以使用了
用法:
webbench -c 并發(fā)數(shù) -t 運(yùn)行測(cè)試時(shí)間 URL
如:
webbench -c 5000 -t 120 http://www.vpser.net
三、ab
ab是apache自帶的一款功能強(qiáng)大的測(cè)試工具
安裝了apache一般就自帶了,
用法可以查看它的說明
$ ./ab
./ab: wrong number of arguments
Usage: ./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 containing 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
-i Use HEAD instead of 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)
-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.
-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)
參數(shù)眾多,一般我們用到的是-n 和-c
例如:
./ab -c 1000 -n 100 http://www.vpser.net/index.php
這個(gè)表示同時(shí)處理1000個(gè)請(qǐng)求并運(yùn)行100次index.php文件.
四、Siege
一款開源的壓力測(cè)試工具,可以根據(jù)配置對(duì)一個(gè)WEB站點(diǎn)進(jìn)行多用戶的并發(fā)訪問,記錄每個(gè)用戶所有請(qǐng)求過程的相應(yīng)時(shí)間,并在一定數(shù)量的并發(fā)訪問下重復(fù)進(jìn)行。
官方:http://www.joedog.org/
Siege下載:http://soft.vpser.net/test/siege/siege-2.67.tar.gz
解壓:
# tar -zxf siege-2.67.tar.gz
進(jìn)入解壓目錄:
# cd siege-2.67/
安裝:
#./configure ; make
#make install
使用
siege -c 200 -r 10 -f example.url
-c是并發(fā)量,-r是重復(fù)次數(shù)。 url文件就是一個(gè)文本,每行都是一個(gè)url,它會(huì)從里面隨機(jī)訪問的。
example.url內(nèi)容:
http://www.licess.cn
http://www.vpser.net
http://soft.vpser.net
結(jié)果說明
Lifting the server siege… done.
Transactions: 3419263 hits //完成419263次處理
Availability: 100.00 % //100.00 % 成功率
Elapsed time: 5999.69 secs //總共用時(shí)
Data transferred: 84273.91 MB //共數(shù)據(jù)傳輸84273.91 MB
Response time: 0.37 secs //相應(yīng)用時(shí)1.65秒:顯示網(wǎng)絡(luò)連接的速度
Transaction rate: 569.91 trans/sec //均每秒完成 569.91 次處理:表示服務(wù)器后
Throughput: 14.05 MB/sec //平均每秒傳送數(shù)據(jù)
Concurrency: 213.42 //實(shí)際最高并發(fā)數(shù)
Successful transactions: 2564081 //成功處理次數(shù)
Failed transactions: 11 //失敗處理次數(shù)
Longest transaction: 29.04 //每次傳輸所花最長(zhǎng)時(shí)間
Shortest transaction: 0.00 //每次傳輸所花最短時(shí)間