Siege是一款开源的压力测试工具,旨在评估WEB应用的抗压能力。根据配置,多个用户同时访问一个WEB站点,记录每个用户的请求过程对应的时间,并在一定的并发访问数下重复。Siege可以从您选择的预设列表中请求随机URL。所以siege可以用来模拟用户请求负载,而ab不行。但不要使用siege来执行***性能基准测试,ab在这方面要准确得多。Siege官网:http://www.joedog.org/1.安装编译安装wgethttp://www.joedog.org/pub/siege/siege-latest.tar.gztar-zxvfsiege-latest.tar.gzcdsiege-2.72/./configuremakemakeinstall通过软件包安装Debian/Ubuntuapt-getinstallsiegeCentOSyuminstallsiege2.详细参数解释命令行参数说明:-C,or–config在屏幕上打印显示当前配置,配置包含在他的配置文件HOME/.siegerc-fFILE,--file=FILE指定使用特定的urls文件运行siege,默认是urls.txt,位于etc/urls.txt-usiege安装目录下的url,--url=URLtests一个指定的URL,并执行“siege”,这个选项会忽略urls文件的设置-b立即进行压力测试。-A,--user-agent="text"设置请求的User-Agentsiegerc配置文件说明:verbose:是否要显示进程。display-id:显示进程时,是否显示模拟用户的idshow-logfile:是否显示运行后的日志信息。logging:是否记录到文件logfile:如果要记录到文件,文件名是什么?Protocol:HTTP通信协议(HTTP/1.1或HTTP/1.0任选其一)connection:keep-alive表示模拟持久连接(writeclose反之亦然)concurrent:模拟有多少用户来抢time:运行一段时间后停止长时间(H=小时,M=分钟,S=秒)代表:每次并发数次。file:在多个目标URL的情况下的URL文件位置。url:单个url情况下指定的urldelay:在非benchmakr的情况下,每个模拟用户从0随机延迟到这个数字(单位:秒)。timeout:套接字连接超时时间(单位:秒)。failures:socket失败次数(超时、连接失败)达到这个次数就停止。互联网:从urls.txt中随机获取url,否则从urls.txt中按顺序获取。benchmark:如果运行benchmark模式,siege在每次连接之间不会有延迟,适合做负载测试。user-agent:发送的代理标识login:WWW-Authenticatelogin(login=jdfulmer:topsecret:Admin)(nonformbased)username,password:alsousedforlogin(non-formbased)LoginURL:第一个登录url每个模拟用户都必须通过(基于表单的)proxy-host,proxy-port,proxy-login:使用代理,填写这个。(proxy-login:jeff:secret:corporate)follow-location:redirectionsupportzero-data-ok:是否接受零长度datachunked:HTTP/1.1requireschunkedencoding3.Usageexamplesiege-c300-r10??0-furl.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.jpghttp://192.168.80.166/02.jpghttp://192.168.80.166/03.jpghttp://192.168.80.166/04.jpghttp://192.168.80.166/05.jpghttp://192.168.80.166/06.jpg结果描述:**SIEGE2.72**Preparing10concurrentusersforbattle.Theserverisnowundersiege..done.Transactions:300hits#Availability:100.00%#CompletedSuccessRateElapsedtime:0.08secs#总时间usedDatatransferred:0.94MB#响应中数据的总大小Responsetime:0.00secs#显示网络连接的速度Transactionrate:3750.00trans/sec#平均每秒完成的事务数Throughput:11.79MB/sec#Average每秒传输数据量Concurrency:8.50#实际最大并发链接数Successfultransactions:300#成功交易数Failedtransactions:0#麻木eroffailedtransactionLongesttransaction:0.01#最长的交易处理时间Shortesttransaction:0.00#最短的交易处理时间4.常用siege命令示例200并发向www.google.com发送请求100次siege-c200-r10??0http://www.google.comListallurlsinurls.txtsiege-c200-r10??0-furls.txt随机选择urls.txt中列出的所有urlsiege-c200-r10??0-furls.txt-idelay=0,压力测试更准确,不是功能测试siege-c200-r10??0-furls.txt-i-b指定httprequestheaderdocumenttypesiege-H"Content-Type:application/json"-c200-r10??0-furls.txt-i-b5.Siege使用的一些总结发送post请求时,url格式为:http://www.xxxx.com/POSTp1=v1&p2=v2如果url中包含空格和汉字,必须先对url进行编码,否则siege发送的请求url不准确。会报如下错误[error]socket:unabletoconnectsock.c:222:Operationalreadyinprogresssocket:connectiontimedout,最终导致测试结果不能超过每秒2W请求,所以放siege-c1000-r100-i-b-furl.txt放在shell中并发执行#!/bin/bashuser_agent="Siege1.0"siege_rc="siege.rc"concurrent=150repet=200siege_single_urls="singleurl.txt"siege_prefix_urls="prefixurl.txt"foriin{1..10}dosiege-c$concurrent-r$repet-i-b-f$siege_single_urls-R$siege_rc-A"$user_agent"&;done6.参考文档http://www.google.comhttp:///吨。cn/Rt8w7Sehttp://www.ha97.com/4663.htmlhttp://longmu.blog.51cto.com/431337/943008
