压力测试工具Siege安装与使用

7,131次阅读
没有评论

压力测试工具 Siege 安装与使用

Siege 是一个 http 负载测试和基准测试工具。可以根据配置对一个 WEB 站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。可以根据配置对一个 WEB 站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。Siege 可以从您选择的预置列表中请求随机的 URL, 然后进行压力测试。

下载与安装:

下载地址: http://download.joedog.org/siege/ 目前最新版本是 2016-05-20 发布的 siege-4.0.2.tar.gz

$ wget http://download.joedog.org/siege/siege-latest.tar.gz
$ tar zxf siege-latest.tar.gz
$ cd siege-4.0.2/
$ ./configure
$ sudo make
$ sudo make install

查看是否安装成功:

 查看 siege 安装路径:
$ which siege
/usr/local/bin/siege

查看 siege 版本:
$ siege -V
SIEGE 4.0.2

参数说明:

可以使用 ”siege -h” 命令来查看帮助信息:

$ siege -h
SIEGE 4.0.2
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.
  -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
 查看当前的配置信息
$ siege -C

使用说明:

(1) 直接请求 URL:

$ siege -c 20 -r 10 http://www.baidu.com

参数说明:-c 是并发量,并发数为 20 人 -r 是重复次数,重复 10 次

(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 /Users/WangYoungTom/temp/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://www.xxxx.com/index.php POST UserId=XXX&StartIndex=0&OS=Android&Sign=cff6wyt505wyt4c
http://www.xxxx.com/articles.php POST UserId=XXX&StartIndex=0&OS=iOS&Sign=cff63w5905wyt4c

使用示例:

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

结果说明:

Transactions: 153 hits (处理次数,本次处理了 153 此请求)
Availability: 100.00 % (可用性 / 成功次数的百分比, 比如本次 100% 成功)
Elapsed time: 17.22 secs(运行时间,本次总消耗 17.22 秒)
Data transferred: 7.70 MB(数据传送量)
Response time: 0.17 secs(响应时间)
Transaction rate: 8.89 trans/sec (处理请求频率,每秒钟处理 8.89 次请求)
Throughput: 0.45 MB/sec(吞吐量, 传输速度)
Concurrency: 1.54 (实际最高并发连接数)
Successful transactions: 153 (成功的传输次数)
Failed transactions: 0 (失败的传输次数)
Longest transaction: 0.70 (处理传输是所花的最长时间)
Shortest transaction: 0.02 (处理传输是所花的最短时间)

使用实例:

$ siege -c 5 -r 10 http://www.baidu.com

Transactions:                386 hits
Availability:             100.00 %
Elapsed time:              37.40 secs
Data transferred:          19.47 MB
Response time:              0.43 secs
Transaction rate:          10.32 trans/sec
Throughput:             0.52 MB/sec
Concurrency:                4.45
Successful transactions:         386
Failed transactions:               0
Longest transaction:            2.38
Shortest transaction:           0.02

// 100 个用户并发请求 10 分钟
siege -c100 -t10 http://localhost
// 100 个用户每个用户请求 10 次
siege -c100 -r10 http://localhost

参考链接

Siege Home https://www.joedog.org/siege-home

Github https://github.com/JoeDog/siege

正文完
 0
VPSWe
版权声明:本站原创文章,由 VPSWe 2017-02-22发表,共计3329字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码