Linux下siege的安裝和實戰

一. siege的安裝

  1. 下載最新版本的siege
wget http://download.joedog.org/siege/siege-latest.tar.gz
  1. 解壓並進入siege路徑
tar -zxvf siege-latest.tar.gz
cd siege-*/
  1. 若是沒有安裝編譯工具,請先安裝
sudo apt-get install build-essential
  1. 編譯安裝
./configure
make
sudo make install
  1. 建立配置文件
siege.config
  1. 修改配置文件
    打開~/.siege/siege.conf文件,修改logfile選項
logfile = $(HOME)/siege.log

打開siege -h看是否安裝成功,打開siege -h能夠看到siege的有關參數
ALTubuntu

二. siege實戰

  1. siege常見參數
    • -c 指定併發數
    • -r 指定重複次數
    • -d 指定請求的延遲時間,注意每一個請求間隨機延遲
    • -f 指定url列表,能夠一次給多個地址加壓
    • -t 指定用例執行時間,好比-t 10s -t 1M(H)之類
    • -g 獲取請求的headers信息並打印出來,debug專用
    • -H 指定請求的headers信息
    • -l或--log=[File] 指定測試結果的路徑
  2. 需求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
  1. 需求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
  1. 需求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
  1. 需求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
相關文章
相關標籤/搜索