Web性能壓力測試工具——Siege詳解
Siege是一款開源的壓力測試工具,設(shè)計用于評估WEB應(yīng)用在壓力下的承受能力。可以根據(jù)配置對一個WEB站點進(jìn)行多用戶的并發(fā)訪問,記錄每個用戶所有請求過程的相應(yīng)時間,并在一定數(shù)量的并發(fā)訪問下重復(fù)進(jìn)行。
Siege可以從您選擇的預(yù)置列表中請求隨機的URL。所以siege可用于仿真用戶請求負(fù)載,而ab則不能。但不要使用siege來執(zhí)行***性能基準(zhǔn)調(diào)校測試,這方面ab就準(zhǔn)確很多。
Siege官網(wǎng):http://www.joedog.org/
一、安裝
- 編譯安裝
- wget http://www.joedog.org/pub/siege/siege-latest.tar.gz
- tar -zxvf siege-latest.tar.gz
- cd siege-2.72/
- ./configure
- make
- make install
- 通過包安裝
Debian/Ubuntu
- apt-get install siege
CentOS
- yum install siege
二、參數(shù)詳解
- 命令行參數(shù)說明:
-C,或–config 在屏幕上打印顯示出當(dāng)前的配置,配置是包括在他的配置文件HOME/.siegerc
-f FILE, –file=FILE 指定用特定的urls文件運行siege ,默認(rèn)為urls.txt,位于siege 安裝目錄下的etc/urls.txt
-u URL,–url=URL 測試指定的一個URL,對它進(jìn)行”siege “,此選項會忽略有關(guān)urls文件的設(shè)定
-b 進(jìn)行壓力測試,不進(jìn)行延時。
-A, —user-agent=”text” 設(shè)置請求的User-Agent
- siegerc設(shè)定檔說明:
verbose :要不要顯示過程。
display-id :顯示過程的時候,要不要顯示模擬user的id
show-logfile :跑完之后要不要顯示log資訊
logging :要不要log到檔案
logfile :要log到檔案的話,檔名是什么
protocol :HTTP通訊協(xié)定( HTTP/1.1或HTTP/1.0 兩者擇一)
connection :keep-alive表示模擬成persistent connection(寫close則反之)
concurrent :模擬有幾個user來沖
time :跑多久之后停止( H=hours, M=minutes, S=seconds)
reps :每一個concurrent沖幾次。
file :多個目的url情形下的url檔案位置。
url :單一url情形下的指定url
delay :非benchmakr行況下,每個模擬user隨機延遲0到這個數(shù)字(單位:秒)。
timeout :socket connection timeout(單位:秒)。
failures :socket失敗次數(shù)(timeouts, connection failures)到達(dá)這個數(shù)字就停下來。
internet :隨機從urls.txt抓出url,否則從urls.txt循序。
benchmark :跑benchmark模式的話,siege將不會在每個connection間delay,適合拿來做load testing.
user-agent :送出的agent識別
login :WWW-Authenticate login( login = jdfulmer:topsecret:Admin )(非form based)
username,password :也是login用的(非form based)
Login URL :每一個模擬user都必需經(jīng)過的***個login url( form based)
proxy-host,proxy-port,proxy-login :使用proxy的話要填這個。(proxy-login: jeff:secret:corporate)
follow-location :redirection support
zero-data-ok :接不接受zero-length data
chunked :HTTP/1.1需要chunked encoding
三、用法舉例
- siege -c 300 -r 100 -f url.txt
說明:-c是并發(fā)量,-r是重復(fù)次數(shù)。url.txt就是一個文本文件,里面是要測試的url,url.txt每行都是一個url。
urls.txt文件是很多行待測試URL的列表以換行符斷開,格式為:
- [protocol://]host.domain.com[:port][path/to/file]
url.txt內(nèi)容:
http://192.168.80.166/01.jpg
http://192.168.80.166/02.jpg
http://192.168.80.166/03.jpg
http://192.168.80.166/04.jpg
http://192.168.80.166/05.jpg
http://192.168.80.166/06.jpg
結(jié)果說明:
- ** SIEGE 2.72
- ** Preparing 10 concurrent users for battle.
- The server is now under siege.. done.
- Transactions: 300 hits #已完成的事務(wù)總署
- Availability: 100.00 % #完成的成功率
- Elapsed time: 0.08 secs #總共使用的時間
- Data transferred: 0.94 MB #響應(yīng)中數(shù)據(jù)的總大小
- Response time: 0.00 secs #顯示網(wǎng)絡(luò)連接的速度
- Transaction rate: 3750.00 trans/sec #平均每秒完成的事務(wù)數(shù)
- Throughput: 11.79 MB/sec #平均每秒傳送的數(shù)據(jù)量
- Concurrency: 8.50 #實際***并發(fā)鏈接數(shù)
- Successful transactions: 300 #成功處理的次數(shù)
- Failed transactions: 0 #失敗處理的次數(shù)
- Longest transaction: 0.01 #最長事務(wù)處理的時間
- Shortest transaction: 0.00 #最短事務(wù)處理時間
四、常用的siege命令舉例
- 200個并發(fā)對www.google.com發(fā)送請求100次
- siege -c 200 -r 100 http://www.google.com
- 在urls.txt中列出所有的網(wǎng)址
- siege -c 200 -r 100 -f urls.txt
- 隨機選取urls.txt中列出所有的網(wǎng)址
- siege -c 200 -r 100 -f urls.txt -i
delay=0,更準(zhǔn)確的壓力測試,而不是功能測試
- siege -c 200 -r 100 -f urls.txt -i -b
指定http請求頭 文檔類型
- siege -H "Content-Type:application/json" -c 200 -r 100 -f urls.txt -i -b
五、Siege使用的一些總結(jié)
- 發(fā)送post請求時,url格式為:http://www.xxxx.com/ POST p1=v1&p2=v2
- 如果url中含有空格和中文,要先進(jìn)行url編碼,否則siege發(fā)送的請求url不準(zhǔn)確
- siege自身感覺也是有瓶頸的,并發(fā)數(shù)***也就1000,再提高就會報下面這樣的錯誤
- [error] socket: unable to connect sock.c:222: Operation already in progress socket: connection timed out
這樣最終導(dǎo)致測試結(jié)果怎么都沒法超過2W每秒的請求,所以就把siege -c 1000 -r 100 -i -b -f url.txt 放到shell中并發(fā)執(zhí)行
- #!/bin/bash
- user_agent="Siege 1.0"
- siege_rc="siege.rc"
- concurrent=150
- repet=200
- siege_single_urls="singleurl.txt"
- siege_prefix_urls="prefixurl.txt"
- for i in {1..10}
- do
- siege -c $concurrent -r $repet -i -b -f $siege_single_urls -R $siege_rc -A "$user_agent" &;
- done
六、參考文檔