压测工具之 siege

下载/安装
Siege时一个开放源代码项目:http://www.joedog.org

下载:
wget ftp://sid.joedog.org/pub/siege/siege-latest.tar.gz

安装:
./configure ; make
#make install

siege包含了一组压力测试工具:
SIEGE (1) Siege是一个HTTP压力测试和评测工具.
使用样例:
任务列表:www.chedong.com.url文件
http://www.chedong.com/tech/
http://www.chedong.com/tech/acdsee.html
http://www.chedong.com/tech/ant.html
http://www.chedong.com/tech/apache_install.html
http://www.chedong.com/tech/awstats.html
http://www.chedong.com/tech/cache.html
http://www.chedong.com/tech/click.html
http://www.chedong.com/tech/cms.html
http://www.chedong.com/tech/compress.html
http://www.chedong.com/tech/cvs_card.html
http://www.chedong.com/tech/default.html
http://www.chedong.com/tech/dev.html
http://www.chedong.com/tech/gnu.html
....

siege -c 20 -r 2 -f www.chedong.com.url 
参数说明:
-c 20 并发20个用户
-r 2 重复循环2次
-f www.chedong.com.url 任务列表:URL列表

输出样例:

** Siege 2.59
** Preparing 20 concurrent users for battle. 这次“战斗”准备了20个并发用户
The server is now under siege.. done. 服务在“围攻”测试中:
Transactions: 40 hits 完成40次处理
Availability: 100.00 % 成功率
Elapsed time: 7.67 secs 总共用时
Data transferred: 877340 bytes 共数据传输:877340字节
Response time: 1.65 secs 相应用时1.65秒:显示网络连接的速度
Transaction rate: 5.22 trans/sec 平均每秒完成5.22次处理:表示服务器后台处理的速度
Throughput: 114385.92 bytes/sec 平均每秒传送数据:114385.92字节
Concurrency: 8.59 最高并发数 8.59
Successful transactions: 40 成功处理次数
Failed transactions: 0 失败处理次数

注意:由于速度很快,可能会达不到并发速度很高就已经完成。Response time显示的是测试机器和被测试服务器之间网络链接状况。Transaction rate则表示服务器端任务处理的完成速度。

辅助工具:
增量压力测试:


为了方便增量压力测试,siege还包含了一些辅助工具:
bombardment (1) 
是一个辅助工具:用于按照增量用户压力测试:
使用样例:
bombardment urlfile.txt 5 3 4 1
初始化URL列表:urlfile.txt
初始化为:5个用户
每次增加:3个用户
运行:4次
每个客户端之间的延迟为:1秒

输出成CSV格式:
siege2csv.pl (1) 
siege2csv.pl将bombardment的输出变成CSV格式:
Time Data Transferred Response Time Transaction Rate Throughput Concurrency Code 200 (note that this is horribly broken.) 
242 60.22 603064 0.02 4.02 10014.35 0.08
605 59.98 1507660 0.01 10.09 25136.05 0.12
938 59.98 2337496 0.02 15.64 38971.26 0.26
1157 60 2883244 0.04 19.28 48054.07 0.78

首先,进行安装:

wget ftp://ftp.joedog.org/pub/siege/siege-latest.tar.gz
tar zxvf siege-latest.tar.gz
cd siege-2.67
./configure
make && make install
安装完成后,就可以开始进行压力测试了
修改siege配置
vi ~/.siegerc
调整:
verbose = false
concurrent = 50
delay = 1
internet = true
benchmark = true




Siege命令常用参数


-c 200 指定并发数200
-r 5 指定测试的次数5
-f urls.txt 制定url的文件
-i internet系统,随机发送url
-b 请求无需等待 delay=0
-t 5 持续测试5分钟
# -r和-t一般不同时使用


常用的siege命令举例


# 200个并发对http://www.google.com发送请求100次


01
siege -c 200 -r 100 http://www.google.com

# 在urls.txt中列出所有的网址


01
siege -c 200 -r 100 -f urls.txt

# 随机选取urls.txt中列出所有的网址


01
siege -c 200 -r 100 -f urls.txt -i

# delay=0,更准确的压力测试,而不是功能测试


01
siege -c 200 -r 100 -f urls.txt -i -b

# 指定http请求头 文档类型


01
siege -H "Content-Type:application/json" -c 200 -r 100 -f urls.txt -i -b

Siege输出结果说明


Transactions: 总共测试次数
Availability: 成功次数百分比
Elapsed time: 总共耗时多少秒
Data transferred: 总共数据传输
Response time: 等到响应耗时
Transaction rate: 平均每秒处理请求数
Throughput: 吞吐率
Concurrency: 最高并发
Successful transactions: 成功的请求数
Failed transactions: 失败的请求数




1、  启动100个用户(线程)在5分钟内对某一页面www.zihou.me进行并发访问


siege http://www.zihou.me -c200 -t5


2、  对多个页面进行并发访问


新建一个文件urls,里面的内容为(只是例子,任何url都可以):


http://www.zihou.me


http://www.zihou.me/2010/12/16/2821/


http://www.zihou.me/2010/12/14/2806/


siege -f urls -c200 -t5


表示启动200个用户在5分钟内并发访问以上的url网址。


并发测试完毕后,会打印出一些结果信息:


Lifting the server siege…      done.


Transactions:                   7555 hits


Availability:                  99.47 %


Elapsed time:                 299.92 secs


Data transferred:              99.17 MB


Response time:                  7.30 secs


Transaction rate:              25.19 trans/sec


Throughput:                     0.33 MB/sec


Concurrency:                  183.84


Successful transactions:        7555


Failed transactions:              40


Longest transaction:           17.94


Shortest transaction:           0.02


如果在并发的过程中,被访问的页面打开出错或及其缓慢,表示在当前并发条件下,被访问网站是不能承受的,也就是抗并发能力弱。


另外,在并发的过程中最好通过top命令来查看CPU和Memory的占用情况



posted @ 2015-04-12 00:47  daino  阅读(392)  评论(0编辑  收藏  举报