性能測試工具--SIEGE安裝及使用簡介 siege壓力測試

 

 

官方網站http://www.joedog.org/ html

概述 

Siege是一個多線程http負載測試和基準測試工具。它有3種操做模式: 
1) Regression (when invoked by bombardment)Siege從配置文件中讀取URLs,按遞歸方式,
逐個發送請求 
2) Internet simulation (Siege從配置文件中讀取URLs,隨機選取URL發送請求) 3) Brute force (在命令行上寫上一個單獨的URL,發送請求)  shell

安裝 多線程

我這裏使用的是最新版的。
$ wget http://www.joedog.org/pub/siege/siege-latest.tar.gz併發

獲得最新包siege-latest.tar.gzdom

解壓之。socket

$ tar xvf siege-latest.tar.gzjsp

獲得的具體版本就是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的具體使用方法很簡單,一般使用時用的比較多的就是併發用戶數和運行時間

$ siege/bin/siege –c 10 –t 60s   http://host/xxx
-c 併發用戶數
-t  運行時間
 這裏的URL有兩種用法,當測試單個地址的時候,直接寫就能夠,如要測試 http://www.cnblogs.com/lrxing/p/3626256.html
$ siege/bin/siege –c 10 –t 60s   http://www.cnblogs.com/lrxing/p/3626256.html
相關文章
相關標籤/搜索