一. 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.csvmagicianyin@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.csvmagicianyin@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