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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1
2
3
4  
5  wget http://www.joedog.org/pub/siege/siege-latest.tar.gz 
6  
7  tar -zxvf siege-latest.tar.gz 
8  
9  cd siege-2.72/ 
10  
11  ./configure 
12  
13  make 
14  
15  make install 
16
17
18
  • 通过包安装

Debian/Ubuntu


1
2
3
4
5
6
7
8
1
2
3
4  
5  apt-get install siege 
6
7
8

CentOS


1
2
3
4
5
6
7
8
1
2
3
4  
5  yum install siege 
6
7
8

二、参数详解

  • 命令行参数说明:

-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
2
3
4
5
6
7
8
1
2
3
4  
5  siege -c 300 -r 100 -f url.txt 
6
7
8

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

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


1
2
3
4
5
6
7
8
1
2
3
4  
5  [protocol://]host.domain.com[:port][path/to/file] 
6
7
8

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

四、常用的siege命令举例

  • 200个并发对www.google.com发送请求100次


1
2
3
4
5
6
7
8
1
2
3
4  
5  siege -c 200 -r 100 http://www.google.com 
6
7
8
  • 在urls.txt中列出所有的网址


1
2
3
4
5
6
7
8
1
2
3
4  
5  siege -c 200 -r 100 -f urls.txt 
6
7
8
  • 随机选取urls.txt中列出所有的网址


1
2
3
4
5
6
7
8
1
2
3
4  
5  siege -c 200 -r 100 -f urls.txt -i 
6
7
8

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


1
2
3
4
5
6
7
8
1
2
3
4  
5  siege -c 200 -r 100 -f urls.txt -i -b 
6
7
8

指定http请求头 文档类型


1
2
3
4
5
6
7
8
1
2
3
4  
5  siege -H "Content-Type:application/json" -c 200 -r 100 -f urls.txt -i -b 
6
7
8

五、Siege使用的一些总结

  • 发送post请求时,url格式为:http://www.xxxx.com/ POST p1=v1&p2=v2

  • 如果url中含有空格和中文,要先进行url编码,否则siege发送的请求url不准确

  • siege自身感觉也是有瓶颈的,并发数最大也就1000,再提高就会报下面这样的错误


1
2
3
4
5
6
7
8
1
2
3
4  
5  [error] socket: unable to connect sock.c:222: Operation already in progress socket: connection timed out 
6
7
8

这样最终导致测试结果怎么都没法超过2W每秒的请求,所以就把siege -c 1000 -r 100 -i -b -f url.txt 放到shell中并发执行


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4  
5  #!/bin/bash 
6  
7  user_agent="Siege 1.0" 
8  
9  siege_rc="siege.rc" 
10  
11  concurrent=150 
12  
13  repet=200 
14  
15  siege_single_urls="singleurl.txt" 
16  
17  siege_prefix_urls="prefixurl.txt" 
18  
19   
20  
21  for i in {1..10} 
22  
23  do 
24  
25  siege -c $concurrent -r $repet -i -b -f $siege_single_urls -R $siege_rc -A "$user_agent" &; 
26  
27  done 
28
29
30

六、参考文档

http://www.google.com

http://t.cn/Rt8w7Se

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

http://www.voidcn.com/article/p-gqkahjtp-sz.html

给TA打赏
共{{data.count}}人
人已打赏
安全经验

图解教程:Google Adsense和百度联…

2021-10-11 16:36:11

安全经验

安全咨询服务

2022-1-12 14:11:49

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索