Siege是一个重压测试和测评工具,设计用于WEB开发这评估应用在重压下的承受能力:可以参考配置对一个WEB站点进行多用户的并发访问,记录每一个用户所有请求过程的相应时间,并在少量的并发访问下重复进行。
Siege 2.73b1 发布,该版本修复了 kfreebsd-* 内核下的编译问题,同时借助 /dev/urandom 来提高随机性。
编译安装
wget http://www.joedog.org/pub/siege/siege-latest.tar.gz
tar -zxvf siege-latest.tar.gz
cd siege-2.72/
./configure
make
make install
通过包安装
Debian/ubuntu
apt-get install siege
centos
yum install siege
2、参数解析
命令行参数说明:
-C,或–config 在屏幕上打印显示出目前的配置,配置是包含在他的配置文件HOME/.siegerc
-f FILE, –file=FILE 指定用特定的urls文件运行siege ,默觉得urls.txt,坐落于siege 安装目录下的etc/urls.txt
-u URL,–url=URL 测试指定的一个URL,对它进行”siege “,此选项会忽视有关urls文件的设定
-b 进行重压测试,不进行延时。
-A, —user-agent=”text” 设置请求的User-Agent
siegerc设定档说明:
verbose :需不需要显示过程。
display-id :显示过程的时候,需不需要显示模拟user的id
show-logfile :跑完之后需不需要显示log资讯
logging :需不需要log到档案
logfile :要log到档案的话,档名是什么
protocol :HTTP通讯协定
connection :keep-alive表示模拟成persistent connection
concurrent :模拟有几个user来冲
time :跑多长时间之后停止
reps :每个concurrent冲几次。
file :多个目的url情形下的url档案地方。
url :单一url情形下的指定url
delay :非benchmakr行况下,每一个模拟user随机延迟0到这个数字。
timeout :socket connection timeout。
failures :socket失败次数到达这个数字就停下来。
internet :随机从urls.txt抓出url,不然从urls.txt循序。
benchmark :跑benchmark模式的话,siege将不会在每一个connection间delay,合适拿来做load testing.
user-agent :送出的agent辨别
login :WWW-Authenticate login
username,password :也是login用的
Login URL :每个模拟user都必需经过的第一个login url
proxy-host,proxy-port,proxy-login :用proxy的话要填这个。
follow-location :redirection support
zero-data-ok :接不同意zero-length data
chunked :HTTP/1.1需要chunked encoding
3、使用方法举例
siege -c 300 -r 100 -f url.txt
说明:-c是并发量,-r是重复次数。url.txt就是一个文本文件,里面是要测试的url,url.txt每行都是一个url。
urls.txt文件是不少行待测试URL的列表以换行符断开,格式为:
[protocol://]host.domain.com[:port][path/to/file]
url.txt内容:
http://192.168.80.166/01.jpg
http://192.168.80.166/02.jpg
http://192.168.80.166/03.jpg
http://192.168.80.166/04.jpg
http://192.168.80.166/05.jpg
http://192.168.80.166/06.jpg
结果说明:
** SIEGE 2.72
** Preparing 10 concurrent users for battle.
The server is now under siege.. done.
Transactions: 300 hits #已完成的事务总署
Availability: 100.00 %#完成的成功率
Elapsed time:0.08 secs#总共用的时间
Data transferred:0.94 MB#响应中数据的总大小
Response time:0.00 secs#显示互联网连接的速度
Transaction rate: 3750.00 trans/sec #平均每秒完成的事务数
Throughput:11.79 MB/sec #平均每秒传送的数据量
Concurrency:8.50 #实质最高并发链接数
Successful transactions: 300 #成功处置的次数
Failed transactions:0#失败处置的次数
Longest transaction:0.01#最长事务处置的时间
Shortest transaction:0.00#最短事务处置时间
4、常见的siege命令举例
200个并发对www.谷歌.com发送请求100次
siege -c 200 -r 100 http://www.谷歌.com
在urls.txt中列出所有些网址
siege -c 200 -r 100 -f urls.txt
随机选取urls.txt中列出所有些网址
siege -c 200 -r 100 -f urls.txt -i
delay=0,更准确的重压测试,而不是功能测试
siege -c 200 -r 100 -f urls.txt -i -b
指定http请求头 文档种类
siege -H Content-Type:application/json -c 200 -r 100 -f urls.txt -i -b
5、Siege用的一些总结
发送post请求时,url格式为:http://www.xxxx.com/ POST p1=v1p2=v2
假如url中含有空格和中文,要先进行url编码,不然siege发送的请求url不准确
siege自己感觉也是有瓶颈的,并发数最大也就1000,再提升就会报下面如此的错误
[error] socket: unable to connect sock.c:222: Operation already in progress socket: connection timed out
如此最后致使测试结果如何都没法超越2W每秒的请求,所以就把siege -c 1000 -r 100 -i -b -f url.txt 放到shell中并发实行
#!/bin/bash
user_agent=Siege 1.0
siege_rc=siege.rc
concurrent=150
repet=200
siege_single_urls=singleurl.txt
siege_prefix_urls=prefixurl.txt
for i in {1..10}
do
siege -c $concurrent -r $repet -i -b -f $siege_single_urls -R $siege_rc -A $user_agent ;
done
转载请说明来源于木蚂蚁软件园(https://www.stgccy.com)
本文地址:https://www.stgccy.com/xz/1568.html
郑重声明:文章来源于网络作为参考,本站仅用于分享不存储任何下载资源,如果网站中图片和文字侵犯了您的版权,请联系我们处理!邮箱3450399331@qq.com