一. siege的安裝
- 下載最新版本的siege
wget http://download.joedog.org/siege/siege-latest.tar.gz
- 解壓並進入siege路徑
tar -zxvf siege-latest.tar.gz
cd siege-*/
- 如果沒有安裝編譯工具,請先安裝
sudo apt-get install build-essential
- 編譯安裝
./configure
make
sudo make install
- 創建配置文件
siege.config
- 修改配置文件
打開~/.siege/siege.conf文件,修改logfile選項
logfile = $(HOME)/siege.log
打開siege -h看是否安裝成功,打開siege -h可以看到siege的有關參數
二. siege實戰
- siege常見參數
- -c 指定並發數
- -r 指定重復次數
- -d 指定請求的延遲時間,注意每個請求間隨機延遲
- -f 指定url列表,可以一次給多個地址加壓
- -t 指定用例執行時間,比如-t 10s -t 1M(H)之類
- -g 獲取請求的headers信息並打印出來,debug專用
- -H 指定請求的headers信息
- -l或--log=[File] 指定測試結果的路徑
- 需求1:使用siege對多個頁面進行加壓
使用siege對多個頁面加壓,並且並發數是5,運行1分鍾
頁面URL:http://ur.tencent.com/categories/7
http://ur.tencent.com/categories/7/?page=2
http://ur.tencent.com/categories/7/?page=3
在虛擬機ubuntu訪問上面三條連接,並發數是5,持續運行1分鍾
magicianyin@ubuntu:~/test$ siege -c 5 -t 1M -f url.txt
Lifting the server siege... done.
Transactions: 345 hits
Availability: 100.00 %
Elapsed time: 59.73 secs
Data transferred: 1.88 MB
Response time: 0.36 secs
Transaction rate: 5.78 trans/sec
Throughput: 0.03 MB/sec
Concurrency: 2.10
Successful transactions: 345
Failed transactions: 0
Longest transaction: 27.16
Shortest transaction: 0.21
- 需求2:保存siege日志
將log保存在result.csv,並且打開result.csv
magicianyin@ubuntu:~/test$ siege -c 5 -t 1M -f url.txt --log=result.csv
magicianyin@ubuntu:~/test$ more result.csv
Date & Time, Trans, Elap Time, Data Trans, Resp Time, Trans Rate, Throughput, Concurrent, OKAY, Failed
2018-02-07 04:10:10, 160, 59.30, 0, 0.35, 2.70, 0.00, 0.95, 160, 4
- 需求3:壓測時候啟用gzip壓縮
Accept-Encoding設置成gzip,並將log保存在result_gzip.csv,並且打開result_gzip.csv
magicianyin@ubuntu:~/test$ siege -c 5 -t 1M -f url.txt -H "Accept-Encoding:gzip" --log=result_gzip.csv
magicianyin@ubuntu:~/test$ more result_gzip.csv
Date & Time, Trans, Elap Time, Data Trans, Resp Time, Trans Rate, Throughput, Concurrent, OKAY, Failed
2018-02-07 04:22:44, 197, 59.83, 1, 0.35, 3.29, 0.02, 1.14, 197, 3
- 需求4:對移動站點進行壓測
將user-agent設置成iPhone發送給服務器
magicianyin@ubuntu:~/test$ siege -c 1 -r 1 -A "Apple-iPhone5C2/1001.525" http://www.baidu.com
Transactions: 1 hits
Availability: 100.00 %
Elapsed time: 0.09 secs
Data transferred: 0.00 MB
Response time: 0.08 secs
Transaction rate: 11.11 trans/sec
Throughput: 0.01 MB/sec
Concurrency: 0.89
Successful transactions: 1
Failed transactions: 0
Longest transaction: 0.08
Shortest transaction: 0.08