码迷,mamicode.com
首页 > 其他好文 > 详细

性能测试--siege

时间:2018-01-25 21:45:40      阅读:868      评论:0      收藏:0      [点我收藏+]

标签:android   参数说明   shell   语言   测试   传输数据   hone   iphone5   分享   

siege

这是Linux系统下的一个测试工具,完全使用C语言实现,可以对HTTP和FTP服务器进行负载和性能测试。通过使用Siege 提供的功能,可以很容易的制定测试计划:包括规定使用并发用户数、重复数量,从而可以模拟在服务器、网络或者其它对象上附加负载以测试他们提供服务的受压能力,方便的测试服务器的性能。最后,利用Siege提供的测试结果来分析性能指标或者分析他们提供的服务在不同负载条件下的性能情况,分析测试结果,找出影响系统性能的瓶颈。

一、安装下载

在linux服务器上操作

1、下载最新版本的siege

wget http://download.joedog.org/siege/siege-latest.tar.gz

2、解压并进入siege路径

tar -zxvf siege-latest.tar.gz
cd siege-*/

3、编译安装

./configure
make
sudo make install

4、验证安装是否成功

siege -h

 

 

二、输入输出参数说明

1、输入参数:

技术分享图片

2、输出参数:

siege示例,使用siege对ur.tencent.com进行加压(模拟20个用户同时访问,一共跑3个循环)

siege -c 20 -r 3 http://ur.tencent.com

测试结果:

技术分享图片

输出参数解释说明:

    • Transactions:   siege对服务器的访问次数。如果页面发生了redirect,那么siege会将跳转过的请求算成是另一个transaction
    • Availability:   socket连接的成功率。算法是,如果页面发生了timeout,4xx,5xx,那么该请求算是失败请求,成功率就等于(所有请求-失败请求) / 总请求数
    • Elapsed time:   所有请求耗费的时间
    • Data transferred: 所有请求传输的数据量,包括请求的headers和content。所以这个数值可能比server端统计的数值要大一点
    • Response time: 平均响应时间
    • Transaction rate: Transactions / Elapsed time
    • Throughput: 每秒平均传输的数据量
    • Concurrency: 平均并发的请求数
    • Successful transactions: 所有status code < 400的transactions数量
    • Failed transactions: 所有status code >= 400的transactions数量
    • Longest transaction: 最耗时的请求时间
    • Shortest transaction: 最短单个请求时间

 

 

三、siege示例:

技术分享图片
http://ur.tencent.com/categories/7
http://ur.tencent.com/categories/7/?page=2
http://ur.tencent.com/categories/7/?page=3
urls.txt

urls.txt文本中保存了多个页面url

 

1、使用siege对urls.txt进行加压,并发数是5,持续运行1分钟

siege -c 5 -t 1M -f urls.txt  

 

2、对多个页面加压后,保存siege日志

siege -c 5 -t 1M -f urls.txt --log=result.csv  #urls.txt、result.csv两个文件名可带路径

注:

  • 可以使用命令sz result.csv将结果文件拷贝到本地(没有sz命令Ubuntu使用: centOS用yum -y install lrzsz安装既可)
  • 也可以用Xshell 5中的sftp工具:get result.csv 下载文件到Xshell 本地Sessions文件夹中

 

3、压测时候启用gzip压缩

gzip压缩就是指服务器在返回请求时候先将请求压缩一下,以减少response的体积,客户端收到response之后会自行解压,这是提升传输速度的一般做法。在请求头中加入Accept-Encoding:gzip就可以告诉服务器返回压缩后的response

siege -c 5 -t 1M -f urls.txt -H "Accept-Encoding:gzip" --log=result_gip.csv

  

 4、模拟移动站点(移动端:Android、iOS)访问进行压测

需要发送相应的user-agent,服务器就会根据这个值判断浏览器是移动版还是桌面版,在这里用iphone的user-agent模拟iPhone5对百度站点进行访问。(iphone的user-agentchrome的user-agent安卓ios主流浏览器User-Agent汇总

siege -c1 -r1 -A"Apple-iPhone5C2/1001.525" http://www.baidu.com
技术分享图片
siege -c1 -r1 -A"Apple-iPhone5C2/1001.525" http://www.baidu.com
[alert] Zip encoding disabled; siege requires zlib support to enable it
** SIEGE 4.0.4
** Preparing 1 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.09 secs:    2925 bytes ==> GET  /
HTTP/1.1 200     0.07 secs:    2340 bytes ==> GET  /static/index/u.png

Transactions:                   2 hits
Availability:              100.00 %
Elapsed time:                0.16 secs
Data transferred:            0.01 MB
Response time:                0.08 secs
Transaction rate:           12.50 trans/sec
Throughput:                0.03 MB/sec
Concurrency:                1.00
Successful transactions:           2
Failed transactions:               0
Longest transaction:            0.09
Shortest transaction:            0.07
移动版输出结果

 

 

桌面版:

siege -c1 -r1  http://www.baidu.com
技术分享图片
** SIEGE 4.0.4
** Preparing 1 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.14 secs:  112430 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.05 secs:      91 bytes ==> GET  /img/gs.gif
[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Operation now in progress
HTTP/1.1 200     0.13 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png

Transactions:                   6 hits
Availability:               85.71 %
Elapsed time:                0.54 secs
Data transferred:            0.21 MB
Response time:                0.08 secs
Transaction rate:           11.11 trans/sec
Throughput:                0.38 MB/sec
Concurrency:                0.93
Successful transactions:           6
Failed transactions:               1
Longest transaction:            0.14
Shortest transaction:            0.05
桌面版输出结果

 

 

对比移动版和桌面版的发现在同样的并发量和循环次数上,移动版的传输数据的量更小(因为移动端流量毕竟贵嘛)

性能测试--siege

标签:android   参数说明   shell   语言   测试   传输数据   hone   iphone5   分享   

原文地址:https://www.cnblogs.com/Keep-Ambition/p/8342479.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!