Web性能壓力測試工具――Siege詳解
2016-09-14 11:09:00 來源:來源:運維之美 評論:0 點擊:
Siege是一款開源的壓力測試工具,設計用于評估WEB應用在壓力下的承受能力。可以根據配置對一個WEB站點進行多用戶的并發訪問,記錄每個用戶所有請求過程的相應時間,并在一定數量的并發訪問下重復進行。
Siege可以從您選擇的預置列表中請求隨機的URL。所以siege可用于仿真用戶請求負載,而ab則不能。但不要使用siege來執行最高性能基準調校測試,這方面ab就準確很多。
Siege官網: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
二、參數詳解
- 命令行參數說明:
-C,或–config 在屏幕上打印顯示出當前的配置,配置是包括在他的配置文件HOME/.siegerc
-f FILE, –file=FILE 指定用特定的urls文件運行siege ,默認為urls.txt,位于siege 安裝目錄下的etc/urls.txt
-u URL,–url=URL 測試指定的一個URL,對它進行”siege “,此選項會忽略有關urls文件的設定
-b 進行壓力測試,不進行延時。
-A, —user-agent=”text” 設置請求的User-Agent
- siegerc設定檔說明:
verbose :要不要顯示過程。
display-id :顯示過程的時候,要不要顯示模擬user的id
show-logfile :跑完之后要不要顯示log資訊
logging :要不要log到檔案
logfile :要log到檔案的話,檔名是什么
protocol :HTTP通訊協定( 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到這個數字(單位:秒)。
timeout :socket connection timeout(單位:秒)。
failures :socket失敗次數(timeouts, connection failures)到達這個數字就停下來。
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都必需經過的第一個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是并發量,-r是重復次數。url.txt就是一個文本文件,里面是要測試的url,url.txt每行都是一個url。
urls.txt文件是很多行待測試URL的列表以換行符斷開,格式為:
- [protocol://]host.domain.com[:port][path/to/file]
url.txt內容:
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
結果說明:
- ** SIEGE 2.72
- ** Preparing 10 concurrent users for battle.
- The server is now under siege.. done.
- Transactions: 300 hits #已完成的事務總署
- Availability: 100.00 % #完成的成功率
- Elapsed time: 0.08 secs #總共使用的時間
- Data transferred: 0.94 MB #響應中數據的總大小
- Response time: 0.00 secs #顯示網絡連接的速度
- Transaction rate: 3750.00 trans/sec #平均每秒完成的事務數
- Throughput: 11.79 MB/sec #平均每秒傳送的數據量
- Concurrency: 8.50 #實際最高并發鏈接數
- Successful transactions: 300 #成功處理的次數
- Failed transactions: 0 #失敗處理的次數
- Longest transaction: 0.01 #最長事務處理的時間
- Shortest transaction: 0.00 #最短事務處理時間
四、常用的siege命令舉例
- 200個并發對www.google.com發送請求100次
- siege -c 200 -r 100 http://www.google.com
- 在urls.txt中列出所有的網址
- siege -c 200 -r 100 -f urls.txt
- 隨機選取urls.txt中列出所有的網址
- siege -c 200 -r 100 -f urls.txt -i
delay=0,更準確的壓力測試,而不是功能測試
- 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使用的一些總結
- 發送post請求時,url格式為:http://www.xxxx.com/ POST p1=v1&p2=v2
- 如果url中含有空格和中文,要先進行url編碼,否則siege發送的請求url不準確
- siege自身感覺也是有瓶頸的,并發數最大也就1000,再提高就會報下面這樣的錯誤
- [error] socket: unable to connect sock.c:222: Operation already in progress socket: connection timed out
這樣最終導致測試結果怎么都沒法超過2W每秒的請求,所以就把siege -c 1000 -r 100 -i -b -f url.txt 放到shell中并發執行
- #!/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
六、參考文檔
http://longmu.blog.51cto.com/431337/943008
上一篇:互聯網運營人必須學會的的14款工具神器
下一篇:大型網站運維工程師的職責和前景
