Siege安装与使用并发性能压力测试工具

siege 是Linux/Unix下的一个WEB系统的压力性能测试工具,

官网地址https://www.joedog.org/siege-home

目前最新版本是siege-4.0.4

下载编译安装openssl 来支持https协议压测

# wget http://www.openssl.org/source/openssl-1.0.2g.tar.gz

# tar zxvf openssl-1.0.2g.tar.gz

# cd openssl-1.0.2g/

# ./config

# make depend

# make install

在确保我们有openssl / libssl之后,我们可以从源代码安装siege并指定“--with-ssl”,在安装完成后,这样就可以使用siege来测试http和https站点

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

# tar zxvf siege-latest.tar.gz

# cd siege-4.0.4/

# ./configure --with-ssl

# make

# make install

创建日志存储目录默认目录

# mkdir  -p /usr/local/var/log/

[root@hongsin-monitor data]# siege -V

SIEGE 4.0.4

Copyright (C) 2017 by Jeffrey Fulmer, et al.

This is free software; see the source for copying conditions.

There is NO warranty; not even for MERCHANTABILITY or FITNESS

FOR A PARTICULAR PURPOSE.

参数说明:
可以使用"siege -h"命令来查看帮助信息:

[root@hongsin-monitor data]# siege -h
SIEGE 4.0.4
Usage: siege [options]
       siege [options] URL
       siege -g URL
Options:
  -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


使用说明:
(1) 直接请求URL:

siege -c 200 -r 100  -l http://www.xxx.com

参数说明: -c 是并发量,并发数为200人 -r 是重复次数, 重复100次 –l 生成报告到日志文件

(2) 随机选取urls.txt中列出所有的网址

在当前目录下创建一个名为"urls-demo.txt"的文件。 文件里边填写URL地址,可以有多条,每行一条,比如:

# URLs:
http://www.sogou.com/web?query=php&from=wang_yong_tao
https://www.baidu.com/

执行

siege -c 5 -r 10 -f urls-demo.txt $ siege -c 5 -r 10 -f /tmp/urls-demo.txt

参数说明: -c 是并发量,并发数为5人 -r 是重复次数, 重复10次 -f 指定使用文件,urls-demo.txt就是一个文本文件,每行都是一个url,会从里面随机访问的

Siege从Siege-V2.06起支持POST和GET两种请求方式。 如果想模拟POST请求,可以在urls-demo.txt中安装一下格式填写URL:

# URL (POST):
http://xxx.com/index.php POST UserId=XXX&StartIndex=0&OS=Android&Sign=cff6wyt505wyt4c
http://xxx.com/articles.php POST UserId=XXX&StartIndex=0&OS=iOS&Sign=cff63w5905wyt4c

使用示例:

// 请求http://www.xxx.com,并发人数为10,重复5次,每次请求间隔3
$ siege --concurrent=10 --reps=5 --delay=3 http://www.xxx.com
$ siege -c 10 -r 5 -d 3 http://www.xxx.com

发送POST请求
新建参数文件

vim uncollect.json
{
    "token":"c23f5fac69190de92a50973803409811",
    "type":0,
    "uni_id":"1acbb47a1d4f7b1f29cca86de70c84b4"
}

压力测试语句

siege -c 10 -r 30 --H "Content-Type:application/json" "http://47.104.18.17:9005/api/v1.0/user/collect?appName=leqv&version=99&build=1.0.0&os=ios&channel=appstore  POST < ./uncollect.json"

以上语句的意思就是:加一个headers头的 Content-Type:application/json 然后POST发送uncollect.json中的数据

Siege输出结果说明

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

模拟移动站点(移动端:Android、iOS)访问进行压测
需要发送相应的user-agent,服务器就会根据这个值判断浏览器是移动版还是桌面版,在这里用iphone的user-agent模拟iPhone5对百度站点进行访问。

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
1、发送post请求时,url格式为:http://www.xxxx.com/ POST p1=v1&p2=v2
2、如果url中含有空格和中文,要先进行url编码,否则siege发送的请求url不准确
3siege -C 可以查看相关的配置参数,可以自行修改,比如是否显示log,超时时间
4siege –l 可以指定生成日志文件
 
 

 

posted @ 2020-12-14 15:53  溪水西流~军  阅读(344)  评论(0)    收藏  举报