概述
Siege是一個多線程http負載測試和基准測試工具。它有3種操作模式:
1) Regression (when invoked by bombardment)Siege從配置文件中讀取URLs,按遞歸方式,
逐個發送請求
2) Internet simulation (Siege從配置文件中讀取URLs,隨機選取URL發送請求) 3) Brute force (在命令行上寫上一個單獨的URL,發送請求)
安裝
我這里使用的是最新版的。
$ wget http://www.joedog.org/pub/siege/siege-latest.tar.gz
得到最新包siege-latest.tar.gz
解壓之。
$ tar xvf siege-latest.tar.gz
得到的具體版本就是siege-3.0.6
$ cd siege-3.0.6/
編譯的時候,我只制定了安裝目錄:/usr/local/siege/
$ ./configure --prefix=/usr/local/siege/
$ make
$ make install
安裝完成后,查看一下安裝目錄下具體都有哪些目錄:
$ ll /usr/local/siege/
結果如下:
drwxr-xr-x 2 root root 4096 Jun 11 15:48 bin
drwxr-xr-x 2 root root 4096 Jun 11 15:48 etc
drwxr-xr-x 5 root root 4096 Jun 11 15:48 man
然后使用/usr/local/siege/bin/siege -help來查看是否真的安裝成功了:
$ siege/bin/siege –help
如果看到如下信息,則說明安裝成功了:
** SIEGE 3.0.6
** Preparing 15 concurrent users for battle.
The server is now under siege...
done.
siege aborted due to excessive socket failure; you
can change the failure threshold in $HOME/.siegerc
Transactions: 0 hits
Availability: 0.00 %
Elapsed time: 36.31 secs
Data transferred: 0.00 MB
Response time: 0.00 secs
Transaction rate: 0.00 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 0.00
Successful transactions: 0
Failed transactions: 1038
Longest transaction: 0.00
Shortest transaction: 0.00
調用
Siege以命令行方式使用,調用格式如下: siege [options]
siege [options] [url] siege -g [url]
Siege的選項說明: -V , --version
打印siege的版本信息
-h , --help 打印幫助信息
-C , --config
打印當前配置。這個選項讀取 .siegerc 並打印。你可以通過編輯$HOME/.siegerc修改配置。如果沒有這個文件,你可以運行siege.config(/usr/local/bin/siege.config )來生成此文件。
-v , --verbose
打印詳細信息。包含請求的協議、響應碼、請求的URL
-g URL , --get URL
獲得一個HTTP事務。導出headers和顯示HTTP交易。對於debug有所幫助。
-c NUM , --concurrent=NUM 並發用戶數(必需參數)。
-i , --internet
此選項配合URLs的配置文件使用。每個虛擬用戶每次請求的URL是隨機從配置文件的獲取。
-t NUMm , --time=NUMm
設置測試運行的時間。單位S\M\H代表秒\分\時。單位大小寫不敏感。數字和單位之間不要有空格。
-f FILE , --file=FILE
被測試的URLs配置文件。默認$SIEGE_HOME/etc/urls.txt
- l , --log
記錄統計信息到$SIEGE_HOME/var/siege.log
- m MESSAGE , --mark=MESSAGE
此選項允許你使用分隔符標記日志文件。沒必要與'-l'同時使用。
-d NUM , --delay=NUM
Time DELAY, random delay before each requst between 1 and NUM. (NOT COUNTED IN STATS)
-b , --benchmark
BENCHMARK, runs the test with NO DELAY for throughput benchmarking. 負載測試時不推薦使用。
-H HEADER , --header=HEADER
HEADER, 該選項允許你添加額外的頭信息。
R SIEGERC , --rc=SIEGERC
設置運行參數配置文件。 默認 $HOME/.siegerc
-A "User Agent" , --user-agent="User Agent" AGENT, 定制客戶端信息。
當一次測試中需要多個URL時,可以將URLs放到一個單獨的文件中。默認$SIEGE_HOME/etc/urls.txt
例如:urls.txt
# 這里表述注釋,一行一個URL
http://homer.whoohoo.com/index.html
http://homer.whoohoo.com/howto.jsp
http://go.whoohoo.com/cgi-bin/q.cgi?scope=a
http://go.whoohoo.com/cgi-bin/q.cgi POST scope=a
http://homer.whoohoo.com/my.jsp POST a=1&b=2
# POST文件
www.haha.com/aha.jsp POST </home/jeff/my.txt
www.haha.com/parser.jsp POST <./my.txt
Siege一次性將文件讀入內存,按照文件中順序發送請求。[-i]選項可以隨機發送URL請求。
在文件中,我們可以設置和引用變量。先定義后引用原則。一個變量一行,類似於shell變量,引用時用$()或者${},如 HOST = homer.whoohoo.com http://${HOST}/index.html
如果變量不存在,則表示空字符串。
使用
siege的具體使用方法很簡單,通常使用時用的比較多的就是並發用戶數和運行時間