Web性能压力测试工具——Siege详解

原文地址:http://os.51cto.com/art/201609/517257.htm

Siege是一款开源的压力测试工具,设计用于评估WEB应用在压力下的承受能力。可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。

Siege是一款开源的压力测试工具,设计用于评估WEB应用在压力下的承受能力。可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。

Siege可以从您选择的预置列表中请求随机的URL。所以siege可用于仿真用户请求负载,而ab则不能。但不要使用siege来执行最高性能基准调校测试,这方面ab就准确很多。

Siege官网:http://www.joedog.org/

一、安装

  • 编译安装
 
 
  1. wget http://www.joedog.org/pub/siege/siege-latest.tar.gz 
  2. tar -zxvf siege-latest.tar.gz 
  3. cd siege-2.72/ 
  4. ./configure 
  5. make 
  6. make install 
  • 通过包安装

Debian/Ubuntu

 
 
  1. apt-get install siege 

CentOS

 
 
  1. yum install siege 

二、参数详解

  • 命令行参数说明:

-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通讯协定( HTTP/1.1或HTTP/1.0 两者择一)

connection :keep-alive表示模拟成persistent connection(写close则反之)

concurrent :模拟有几个user来冲

time :跑多久之后停止( H=hours, M=minutes, S=seconds)

reps :每一个concurrent冲几次。

file :多个目的url情形下的url档案位置。

url :单一url情形下的指定url

delay :非benchmakr行况下,每个模拟user随机延迟0到这个数字(单位:秒)。

timeout :socket connection timeout(单位:秒)。

failures :socket失败次数(timeouts, connection failures)到达这个数字就停下来。

internet :随机从urls.txt抓出url,否则从urls.txt循序。

benchmark :跑benchmark模式的话,siege将不会在每个connection间delay,适合拿来做load testing.

user-agent :送出的agent识别

login :WWW-Authenticate login( login = jdfulmer:topsecret:Admin )(非form based)

username,password :也是login用的(非form based)

Login URL :每一个模拟user都必需经过的第一个login url( form based)

proxy-host,proxy-port,proxy-login :使用proxy的话要填这个。(proxy-login: jeff:secret:corporate)

follow-location :redirection support

zero-data-ok :接不接受zero-length data

chunked :HTTP/1.1需要chunked encoding

三、用法举例

 
 
  1. siege -c 300 -r 100 -f url.txt 

说明:-c是并发量,-r是重复次数。url.txt就是一个文本文件,里面是要测试的url,url.txt每行都是一个url。

urls.txt文件是很多行待测试URL的列表以换行符断开,格式为:

 
 
  1. [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

结果说明:

 
 
  1. ** SIEGE 2.72 
  2. ** Preparing 10 concurrent users for battle. 
  3. The server is now under siege..      done. 
  4.  
  5. Transactions:                 300 hits  #已完成的事务总署 
  6. Availability:              100.00 %   #完成的成功率 
  7. Elapsed time:                0.08 secs   #总共使用的时间 
  8. Data transferred:            0.94 MB   #响应中数据的总大小 
  9. Response time:                0.00 secs   #显示网络连接的速度 
  10. Transaction rate:         3750.00 trans/sec  #平均每秒完成的事务数 
  11. Throughput:               11.79 MB/sec  #平均每秒传送的数据量 
  12. Concurrency:                8.50  #实际最高并发链接数 
  13. Successful transactions:         300  #成功处理的次数 
  14. Failed transactions:               0    #失败处理的次数 
  15. Longest transaction:            0.01   #最长事务处理的时间 
  16. Shortest transaction:            0.00   #最短事务处理时间 

四、常用的siege命令举例

  • 200个并发对www.google.com发送请求100次
 
 
  1. siege -c 200 -r 100 http://www.google.com 
  • 在urls.txt中列出所有的网址
 
 
  1. siege -c 200 -r 100 -f urls.txt 
  • 随机选取urls.txt中列出所有的网址
 
 
  1. siege -c 200 -r 100 -f urls.txt -i 

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

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

指定http请求头 文档类型

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

五、Siege使用的一些总结

  • 发送post请求时,url格式为:http://www.xxxx.com/ POST p1=v1&p2=v2
  • 如果url中含有空格和中文,要先进行url编码,否则siege发送的请求url不准确
  • siege自身感觉也是有瓶颈的,并发数最大也就1000,再提高就会报下面这样的错误
 
 
  1. [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中并发执行

 
 
  1. #!/bin/bash 
  2. user_agent="Siege 1.0" 
  3. siege_rc="siege.rc" 
  4. concurrent=150 
  5. repet=200 
  6. siege_single_urls="singleurl.txt" 
  7. siege_prefix_urls="prefixurl.txt" 
  8.  
  9. for i in {1..10} 
  10. do 
  11. siege -c $concurrent -r $repet -i -b -f $siege_single_urls -R $siege_rc -A "$user_agent" &; 
  12. done 

六、参考文档

http://www.google.com

http://t.cn/Rt8w7Se

http://www.ha97.com/4663.html

http://longmu.blog.51cto.com/431337/943008


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很好用的网络压力测试工具 Linux版 siege的安装 unzip filename.zip cd siege-*.*.* ./configure --prefix=/usr/local/siege --mandir=/usr/local/man --with-ssl=/usr/local/ssl mkdir -p /usr/local/siege/etc mkdir -p /usr/local/siege/var make make install 查看配置文件 /usr/local/siege/bin/siege -C 二、siege的使用 举例说明: 50个用户(每次并发量)重复100次 共产生 50*100 个请求 /usr/local/siege/bin/siege -c 50 -r 100 www.baidu.com 50个用户 重复100次 发送GET参数 /usr/local/siege/bin/siege -c 50 -r 100 http://www.baidu.com/s?wd=siege&rsv_spt=1&issp=1&rsv_bp=0&ie=utf-8&tn=baiduhome_pg&rsv_sug3=4&rsv_sug=2&rsv_sug1=4&rsv_sug4=60 50个用户 重复100次 发送POST参数 (注意引号) /usr/local/siege/bin/siege -c 50 -r 100 "https://www.abc.com/a.php POST name=zhangsan" 50个用户 重复100次 发送POST参数(从文件中读取) /usr/local/siege/bin/siege -c 50 -r 100 "https://www.abc.com/a.php POST < /root/ab_test/post.xml" 另外还有挺多参数 详情请man 或 siege -h siege报表解析,请man查看,暂略(有点累了,不想写了。。。。。)。 Transactions: 10 hits :服务器接收的请求数 Availability: 100.00 % :有效情况的比例 Elapsed time: 1.06 secs : 测试所用的时间 Data transferred: 0.04 MB :每个模拟用户的数据传输量 Response time: 0.03 secs :响应每个模拟用户请求的平均时间 Transaction rate: 9.43 trans/sec :服务器每秒处理事务的平均数 Throughput: 0.04 MB/sec :服务器每秒跟所有模拟用户的数据传输量 Concurrency: 0.25 :每秒的模拟连接 Successful transactions: 10 :处理成功的事务数(code<400) Failed transactions: 0 : 处理失败的事务数(code>400) Longest transaction: 0.04 :最长的事务处理时间 Shortest transaction: 0.02 :最短的事务处理时间

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值