(三)siege的使用

学习:

ELK——http://dockone.io/article/3655    

docker——http://www.testclass.net/docker/   

Android Monkey压力测试——https://blog.csdn.net/jieqiang3/article/details/53928638

线上性能监控——https://testerhome.com/topics/11725

一、siege的安装

  • 服务器centos6.5
  • siege版本: 4.0.2

目的

  • 熟悉linux服务器上软件安装
  • 熟悉使用命令行测试工具
  • 学会使用最简单的压力发生器
  • 学会查看性能测试结果

安装步骤

 1、下载:

[root@ siege-4.0.4]# wget http://download.joedog.org/siege/siege-4.0.4.tar.gz

2、解压:

[root@ siege-4.0.4]# tar zxvf siege-4.0.4.tar.gz

3、打开解压包:

[root@ siege-4.0.4]# cd siege-4.0.4

4、执行

[root@ siege-4.0.4]# ./configure

5、安装:

[root@ siege-4.0.4]# make && make install

6、修改配置文件

打开~/.siege/siege.conf文件,修改logfile选项

logfile = $(HOME)/siege.log

二、siege压测实战

场景分析

使用siege对ur.tencent.com进行加压。

要求

  • 模拟20个用户同时访问
  • 一共跑3个循环

脚本

siege是通过命令行运行的,因此没有脚本一说。

实现

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

-c :并发个数 concurrent

-r :循环(重复)次数repeat

测试结果

Transactions: 484 hits
Availability:    92.72 %
Elapsed time:    51.89 secs
Data transferred:    12.28 MB
Response time:    0.56 secs
Transaction rate:    9.33 trans/sec
Throughput:    0.24 MB/sec
Concurrency:    5.26
Successful transactions: 522
Failed transactions:    38
Longest transaction:    37.10
Shortest transaction:    0.02

结果字段含义

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

三、siege常用参数

-V, --version             VERSION, prints the version number.
  -h, --help                HELP, prints this section.
  -C, --config              CONFIGURATION, show the current config.
  -v, --verbose             VERBOSE, prints notification to screen.
  -q, --quiet               QUIET turns verbose off and suppresses output.
  -g, --get                 GET, pull down HTTP headers and display the
                            transaction. Great for application debugging.
  -p, --print               PRINT, like GET only it prints the entire page.
  -c, --concurrent=NUM      CONCURRENT users, default is 10
  -r, --reps=NUM            REPS, number of times to run the test.
  -t, --time=NUMm           TIMED testing where "m" is modifier S, M, or H
                            ex: --time=1H, one hour test.
  -d, --delay=NUM           Time DELAY, random delay before each requst
  -b, --benchmark           BENCHMARK: no delays between requests.
  -i, --internet            INTERNET user simulation, hits URLs randomly.
  -f, --file=FILE           FILE, select a specific URLS FILE.
  -R, --rc=FILE             RC, specify an siegerc file
  -l, --log[=FILE]          LOG to FILE. If FILE is not specified, the
                            default is used: PREFIX/var/siege.log
  -m, --mark="text"         MARK, mark the log file with a string.
                            between .001 and NUM. (NOT COUNTED IN STATS)
  -H, --header="text"       Add a header to request (can be many)
  -A, --user-agent="text"   Sets User-Agent in request
  -T, --content-type="text" Sets Content-Type in request
      --no-parser           NO PARSER, turn off the HTML page parser
      --no-follow           NO FOLLOW, do not follow HTTP redirects
  • -c 指定并发数。不指定的话默认10
  • -r 指定循环次数
  • -d 指定思考时间
  • -f 指定url文件,可以一次访问一组url
  • -t 指定运行时间
  • -g 获取请求的headers信息并打印,方便调试
  • -H 指定请求的headers信息
  • -l或--log=[File] 指定测试结果的路径

四、进价实战

1、如果开发对页面的性能进行了调优,我们怎么快速得出页面性能得到提升这样一个结论?

同样的场景在调优前和调优后分别执行,对比结果

  • 同样的场景,即同样的命令
  • 对比结果,如TPS,TPS越高性能越好

2、需求:对ur.tencent.com的下面几个页面进行加压,以便暴露系统的瓶颈。

http://ur.tencent.com/categories/7
http://ur.tencent.com/categories/7/?page=2
http://ur.tencent.com/categories/7/?page=3

希望并发数是5,持续运行1分钟。

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

3、可不可以通过siege来实现随机访问一组url的功能?

增加参数-i 即可实现随机访问

#siege -c 3 -t 1M -i --file=urls.txt

4、对ur.tencent.com的下面几个页面进行加压,以便暴露系统的瓶颈,并将结果记录到日志。

http://ur.tencent.com/categories/7
http://ur.tencent.com/categories/7/?page=2
http://ur.tencent.com/categories/7/?page=3
#siege -c 5 -t 30S -f urls.txt --log=result.csv
  • csv文件可以直接用excel打开
  • 可以使用命令sz result.csv将结果文件拷贝到本地
  • 如果没有sz命令使用intall lrzsz安装既可

5、压测时候启用gzip压缩

请求头中的Accept-Encoding:gzip用来告诉服务器返回压缩后的response

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

6、对移动站点进行压测

headers中的user-agent用来告诉服务器,我是谁,我从哪里来,即告诉服务器是移动端还是电脑端

-A参数可直接指定user-agent

#siege -c1 -r1 -A"Apple-iPhone6C2/1001.525" http://www.baidu.com

模拟iphone6访问http://www.baidu.com

7、可不可以通过siege来实现并发访问RESTFUL风格api的功能?

可使用参数-T 指定返回类型来实现

扩展阅读

HTTP API 与Restful API 关系及区别https://blog.csdn.net/gyshun/article/details/80019741
























猜你喜欢

转载自www.cnblogs.com/loveapple/p/9902082.html
今日推荐