用siege进行web压力测试


Siege(英文意思是围攻)是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
最早使用的压力测试工具是apache的ab(apache benchmark),apache ab做重复压力测试不错,但是每次只能测试一个链接,如何测试一组链接(比如从日志中导出的1个小时的日志,做真实压力测试),后来找到了这个:Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
SIEGE is an http regressive testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a webserver with a configurable number of concurrent simulated users. Those users place the webserver "under siege." The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test.
一些测试指标的概念
1、吞吐率(Requests per second)
概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
计算公式:总请求数 / 处理完成这些请求数所花费的时间,即
Request per second = Complete requests / Time taken for tests
2、并发连接数(The number of concurrent connections)
概念:某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。
3、并发用户数(The number of concurrent users,Concurrency Level)
概念:要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。
4、用户平均请求等待时间(Time per request)
计算公式:处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数),即
Time per request = Time taken for tests /( Complete requests / Concurrency Level)
5、服务器平均请求等待时间(Time per request: across all concurrent requests)
计算公式:处理完成所有请求数所花费的时间 / 总请求数,即
Time taken for / testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也=用户平均请求等待时间/并发用户数,即
Time per request / Concurrency Level
虽然Apache自带一个压力测试工具ab,但是ab的功能太简单了,无法模拟真实的web访问,所以我们要用到更加强大的web压力测试工具--Siege(英文原意:围攻)。设计用于WEB开发这评估应用在压力下的承受能力,可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
首先,进行安装:
wget ftp://ftp.joedog.org/pub/siege/siege-latest.tar.gz
tar zxvf siege-latest.tar.gz
cd siege-2.70
./configure
make && make install
安装完成后,就可以开始进行压力测试了
修改siege配置
vi ~/.siegerc
调整:
verbose = false
concurrent = 50
delay = 1
internet = true
benchmark = true
siege参数介绍:
* -cNUM
设置并发的用户(连接)数量,比如-c10,设置并发10个连接。默认的连接数量可以到~/.siegerc中查看,指令为concurrent = x,前面咱们已经调整了默认并发连接为50。
* -rNUM
(repetitions),重复数量,即每个连接发出的请求数量,设置这个的话,就不需要设置-t了。对应.siegerc配置文件中的reps = x指令
* -tNUM
(time),持续时间,即测试持续时间,在NUM时间后结束,单位默认为分,比如-t10,那么测试时间为10分钟,-t10s,则测试时间为10秒钟。对应.siegerc中的指令为time = x指令
* -b
(benchmark),基准测试,如果设置这个参数的话,那么delay时间为0。在.siegerc中咱们修改为默认开启。
* -f url.txt
(file),这是url列表文件。对应.siegerc配置文件中的file = x指令
测试结果分析:
[root@bbs ~]# siege -c 500 -r 50 -f bbs.url
** SIEGE 2.70
** Preparing 500 concurrent users for battle.
The server is now under siege.. done.
Transactions: 25000 hits
Availability: 100.00 %
Elapsed time: 65.52 secs
Data transferred: 83.65 MB
Response time: 0.57 secs
Transaction rate: 381.56 trans/sec
Throughput: 1.28 MB/sec
Concurrency: 216.02
Successful transactions: 21707
Failed transactions: 0
Longest transaction: 5.83
Shortest transaction: 0.00
上面是用500并发重复测试50次bbs.url里的url列表的结果,下面一条一条地分析测试结果:
Transactions: 25000 hits
意思是总共完成了25000次测试
Availability: 100.00 %
测试的有效性100%
Elapsed time: 65.52 secs
用时65.52秒
Data transferred: 83.65 MB
传输了83.65MB数据
Response time: 0.57 secs
响应时间
Transaction rate: 381.56 trans/sec
每秒传输381.56次
Throughput: 1.28 MB/sec
数据吞吐量每秒1.28MB
Concurrency: 216.02
实际并发访问
Successful transactions: 21707
成功的传输
Failed transactions: 0
失败的传输
Longest transaction: 5.83
每次传输所花最长时间
Shortest transaction: 0.00
每次传输所花最短时间,另外提醒一句,如果你的WEB服务器用的是Apache,请不要将并发数设为大于200。
安装:
%./configure ; make
#make install
siege包含了一组压力测试工具,Siege是一个HTTP压力测试和评测工具。使用样例:
任务列表:www.freeoa.net.url文件
http://www.freeoa.net/tech/
http://www.freeoa.net/tech/acdsee.html
http://www.freeoa.net/tech/ant.html
http://www.freeoa.net/tech/apache_install.html
http://www.freeoa.net/tech/awstats.html
http://www.freeoa.net/tech/cache.html
....
siege -c 20 -r 2 -f www.freeoa.net.url
参数说明:
-c 20 并发20个用户
-r 2 重复循环2次
-f www.freeoa.net.url 任务列表:URL列表
输出样例:
** Siege 2.70
** 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则表示服务器端任务处理的完成速度。
如果测试的站点带登录密码,先用账户和密码登录后,用开发者工具找到标识这个会话的Cookie值(Session ID)记下来,如果只用到一个Cookie,siege | ab -n 100 -C key=value http://192.168.10.127/index.psp,如果需要多个Cookie,就直接设Header:siege -n 100 -H "Cookie: Key1=Value1; Key2=Value2" http://192.168.10.127/index.psp
辅助工具:
增量压力测试:
为了方便增量压力测试,siege还包含了一些辅助工具:
bombardment是一个辅助工具:用于按照增量用户压力测试。
使用样例:
bombardment urlfile.txt 5 3 4 1
初始化URL列表:urlfile.txt
初始化为:5个用户
每次增加:3个用户
运行:4次
每个客户端之间的延迟为:1秒
输出成CSV格式:
siege2csv.pl
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
Introduction
Siege is an http/https regression testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a web server with a configurable number of concurrent simulated users. Those users place the webserver "under siege." The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test. Performance measures include elapsed time of the test, the amount of data transferred ( including headers ), the response time of the server, its transaction rate, its throughput, its concurrency and the number of times it returned OK. These measures are quantified and reported at the end of each run. Their meaning and significance is discussed below. Siege has essentially three modes of operation, regression, internet simulation and brute force. It can read a large number of URLs from a configuration file and run through them incrementally ( regression ) or randomly ( internet simulation ). Or the user may simply pound a single URL with a runtime configuration at the command line ( brute force ).
Authors
Jeffrey Fulmer, et al -- Designed and implemented Siege in his position as Webmaster for Armstrong World Industries
License
Please consult the file, COPYING for complete license information. Copyright (C) 2000-2009 Jeffrey Fulmer, et al. Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the copyright notice and this permission notice are preserved, thus giving the recipient permission to redistribute in turn. Permission is granted to distribute modified versions of this document, or of portions of it, under the above conditions, provided also that they carry prominent notices stating who last changed them.
最新版本:3.0
此版本改变了处理 --reps=once 的方式, 现在它把 urls.txt 均匀的分配给所有的用户,而且文件中的每个 URL 只能点击一次。此版本还包括了一些 bug 修复和文档更新。
项目主页:http://www.joedog.org/siege/
最早使用的压力测试工具是apache的ab(apache benchmark),apache ab做重复压力测试不错,但是每次只能测试一个链接,如何测试一组链接(比如从日志中导出的1个小时的日志,做真实压力测试),后来找到了这个:Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
SIEGE is an http regressive testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a webserver with a configurable number of concurrent simulated users. Those users place the webserver "under siege." The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test.
一些测试指标的概念
1、吞吐率(Requests per second)
概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
计算公式:总请求数 / 处理完成这些请求数所花费的时间,即
Request per second = Complete requests / Time taken for tests
2、并发连接数(The number of concurrent connections)
概念:某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。
3、并发用户数(The number of concurrent users,Concurrency Level)
概念:要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。
4、用户平均请求等待时间(Time per request)
计算公式:处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数),即
Time per request = Time taken for tests /( Complete requests / Concurrency Level)
5、服务器平均请求等待时间(Time per request: across all concurrent requests)
计算公式:处理完成所有请求数所花费的时间 / 总请求数,即
Time taken for / testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也=用户平均请求等待时间/并发用户数,即
Time per request / Concurrency Level
虽然Apache自带一个压力测试工具ab,但是ab的功能太简单了,无法模拟真实的web访问,所以我们要用到更加强大的web压力测试工具--Siege(英文原意:围攻)。设计用于WEB开发这评估应用在压力下的承受能力,可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
首先,进行安装:
wget ftp://ftp.joedog.org/pub/siege/siege-latest.tar.gz
tar zxvf siege-latest.tar.gz
cd siege-2.70
./configure
make && make install
安装完成后,就可以开始进行压力测试了
修改siege配置
vi ~/.siegerc
调整:
verbose = false
concurrent = 50
delay = 1
internet = true
benchmark = true
siege参数介绍:
* -cNUM
设置并发的用户(连接)数量,比如-c10,设置并发10个连接。默认的连接数量可以到~/.siegerc中查看,指令为concurrent = x,前面咱们已经调整了默认并发连接为50。
* -rNUM
(repetitions),重复数量,即每个连接发出的请求数量,设置这个的话,就不需要设置-t了。对应.siegerc配置文件中的reps = x指令
* -tNUM
(time),持续时间,即测试持续时间,在NUM时间后结束,单位默认为分,比如-t10,那么测试时间为10分钟,-t10s,则测试时间为10秒钟。对应.siegerc中的指令为time = x指令
* -b
(benchmark),基准测试,如果设置这个参数的话,那么delay时间为0。在.siegerc中咱们修改为默认开启。
* -f url.txt
(file),这是url列表文件。对应.siegerc配置文件中的file = x指令
测试结果分析:
[root@bbs ~]# siege -c 500 -r 50 -f bbs.url
** SIEGE 2.70
** Preparing 500 concurrent users for battle.
The server is now under siege.. done.
Transactions: 25000 hits
Availability: 100.00 %
Elapsed time: 65.52 secs
Data transferred: 83.65 MB
Response time: 0.57 secs
Transaction rate: 381.56 trans/sec
Throughput: 1.28 MB/sec
Concurrency: 216.02
Successful transactions: 21707
Failed transactions: 0
Longest transaction: 5.83
Shortest transaction: 0.00
上面是用500并发重复测试50次bbs.url里的url列表的结果,下面一条一条地分析测试结果:
Transactions: 25000 hits
意思是总共完成了25000次测试
Availability: 100.00 %
测试的有效性100%
Elapsed time: 65.52 secs
用时65.52秒
Data transferred: 83.65 MB
传输了83.65MB数据
Response time: 0.57 secs
响应时间
Transaction rate: 381.56 trans/sec
每秒传输381.56次
Throughput: 1.28 MB/sec
数据吞吐量每秒1.28MB
Concurrency: 216.02
实际并发访问
Successful transactions: 21707
成功的传输
Failed transactions: 0
失败的传输
Longest transaction: 5.83
每次传输所花最长时间
Shortest transaction: 0.00
每次传输所花最短时间,另外提醒一句,如果你的WEB服务器用的是Apache,请不要将并发数设为大于200。
安装:
%./configure ; make
#make install
siege包含了一组压力测试工具,Siege是一个HTTP压力测试和评测工具。使用样例:
任务列表:www.freeoa.net.url文件
http://www.freeoa.net/tech/
http://www.freeoa.net/tech/acdsee.html
http://www.freeoa.net/tech/ant.html
http://www.freeoa.net/tech/apache_install.html
http://www.freeoa.net/tech/awstats.html
http://www.freeoa.net/tech/cache.html
....
siege -c 20 -r 2 -f www.freeoa.net.url
参数说明:
-c 20 并发20个用户
-r 2 重复循环2次
-f www.freeoa.net.url 任务列表:URL列表
输出样例:
** Siege 2.70
** 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则表示服务器端任务处理的完成速度。
如果测试的站点带登录密码,先用账户和密码登录后,用开发者工具找到标识这个会话的Cookie值(Session ID)记下来,如果只用到一个Cookie,siege | ab -n 100 -C key=value http://192.168.10.127/index.psp,如果需要多个Cookie,就直接设Header:siege -n 100 -H "Cookie: Key1=Value1; Key2=Value2" http://192.168.10.127/index.psp
辅助工具:
增量压力测试:
为了方便增量压力测试,siege还包含了一些辅助工具:
bombardment是一个辅助工具:用于按照增量用户压力测试。
使用样例:
bombardment urlfile.txt 5 3 4 1
初始化URL列表:urlfile.txt
初始化为:5个用户
每次增加:3个用户
运行:4次
每个客户端之间的延迟为:1秒
输出成CSV格式:
siege2csv.pl
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
Introduction
Siege is an http/https regression testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a web server with a configurable number of concurrent simulated users. Those users place the webserver "under siege." The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test. Performance measures include elapsed time of the test, the amount of data transferred ( including headers ), the response time of the server, its transaction rate, its throughput, its concurrency and the number of times it returned OK. These measures are quantified and reported at the end of each run. Their meaning and significance is discussed below. Siege has essentially three modes of operation, regression, internet simulation and brute force. It can read a large number of URLs from a configuration file and run through them incrementally ( regression ) or randomly ( internet simulation ). Or the user may simply pound a single URL with a runtime configuration at the command line ( brute force ).
Authors
Jeffrey Fulmer, et al -- Designed and implemented Siege in his position as Webmaster for Armstrong World Industries
License
Please consult the file, COPYING for complete license information. Copyright (C) 2000-2009 Jeffrey Fulmer, et al. Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the copyright notice and this permission notice are preserved, thus giving the recipient permission to redistribute in turn. Permission is granted to distribute modified versions of this document, or of portions of it, under the above conditions, provided also that they carry prominent notices stating who last changed them.
最新版本:3.0
此版本改变了处理 --reps=once 的方式, 现在它把 urls.txt 均匀的分配给所有的用户,而且文件中的每个 URL 只能点击一次。此版本还包括了一些 bug 修复和文档更新。
项目主页:http://www.joedog.org/siege/
该文章最后由 阿炯 于 2019-04-21 16:08:43 更新,目前是第 2 版。