Siege是一款高性能的、开源的Http压力测试工具,设计用于评估WEB应用在压力下的承受能力。Siege支持身份验证、cookies、http、https和ftp协议。可以根据配置,对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的响应时间,并在一定数量的并发访问下重复进行。
siege可以从您选择的预置列表中请求随机的URL,所以siege可用于仿真用户请求负载,而ab则不能。但不要使用siege来执行最高性能基准调校测试,这方面ab就准确很多。
Siege支持多链接,支持get和post请求,可以对web系统进行多并发下持续请求的压力测试。
解压并安装:
-- yum直接安装
yum install -y siege
-- 也可以编译安装
tar -zxvf siege-latest.tar.gz
cd siege-4.1.1
./configure --with-ssl=/usr/local/openssl
make && make install
[root@docker35 siege-4.1.1]# siege -h
New configuration template added to /root/.siege
Run siege -C to view the current settings in that file
SIEGE 4.1.1
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 request
-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
-j, --json-output JSON OUTPUT, print final stats to stdout as JSON
--no-parser NO PARSER, turn off the HTML page parser
--no-follow NO FOLLOW, do not follow HTTP redirects
Copyright (C) 2021 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.
参数详解:
$HOME/.siegerc
中,可以编辑里面的参数,这样每次siege 都会按照它运行./root/.siege/siege.conf
下的limit数值。/usr/local/var/siege.log
中,也可在.siegerc
中自定义$HOME/.siegerc
参数 | 描述 |
---|---|
Transactions | 命中次数 |
Availability | 命中率 |
Elapsed time | 整个压测花费的时间,从第一个开始到最后一个结束 |
Data transferred | 整个压测数据传输的总和 |
Response time | 响应时间是响应每个模拟用户请求所花费的平均时间 |
Transaction rate | 事务速率是服务器每秒能够处理的平均事务数. 简而言之:事务除以经过的时间 |
Throughput | 吞吐量是从服务器到所有模拟用户每秒传输的平均字节数 |
Concurrency | 并发是同时连接的平均数,这是一个随服务器性能下降而上升的数字 |
Successful transactions | 成功事务次数 |
Failed transactions | 失败事务次数 |
Longest transaction | 最长事务时间 |
Shortest transaction | 最短事务时间 |
[root@docker35 ~]# siege -C
CURRENT SIEGE CONFIGURATION
Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.1.1
Edit the resource file to change the settings.
----------------------------------------------
version: 4.1.1
verbose: true
color: true
quiet: false
debug: false
protocol: HTTP/1.1
HTML parser: enabled
get method: HEAD
connection: close
concurrent users: 25
time to run: n/a
repetitions: n/a
socket timeout: 30
cache enabled: false
accept-encoding: gzip, deflate
delay: 0.000 sec
internet simulation: false
benchmark mode: false
failures until abort: 1024
named URL: none
URLs file: /usr/local/etc/urls.txt
thread limit: 500
logging: false
log file: /usr/local/var/log/siege.log
resource file: /root/.siege/siege.conf
timestamped output: false
comma separated output: false
allow redirects: true
allow zero byte data: true
allow chunked encoding: true
upload unique files: true
json output: false
no-follow:
- ad.doubleclick.net
- pagead2.googlesyndication.com
- ads.pubsqrd.com
- ib.adnxs.com
proxy auth:
www auth:
用法举例:
siege -c 200 -t 10S -i -d 1 -f url.txt
说明:-c是并发量,-t是时间。url.txt就是一个文本文件,每行都是一个url,它会从里面随机访问的。
url.txt文件内容如下:
https://www.xmmup.com/linuxchakanzuixiaohaoneicundejincheng.html
https://www.xmmup.com/changjiandelinuxcaozuoxitongneihecanshu.html
https://www.xmmup.com/
https://www.xmmup.com/neicunfenpeizhongdenuma.html
https://www.xmmup.com/linuxchakanzuixiaohaoneicundejincheng.html
https://www.xmmup.com/phpyouhuakuozhanopcache.html
结果说明:
siege -c 1000 -t 10S https://www.xmmup.com
siege -g https://www.xmmup.com
siege -c 200 -r 100 -f urls.txt
siege -c 200 -r 100 -f urls.txt -i
siege -c 200 -r 100 -f urls.txt -i -b
siege -c1 -r1 "http://192.168.16.101:6005/bpm/processInstances/review PUT <./1.json"
siege -c10 -r1 -p --header="Authorization: Bearer b7c75bae-9d68-4a74-bffb-95eb08a40918" --header="sg: 123456"
siege -H "Content-Type:application/json" -c 200 -r 100 -f urls.txt -i -b