暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

web网站压测工具Siege介绍

DB宝 2021-09-06
1585

简介

Siege是一款高性能的、开源的Http压力测试工具,设计用于评估WEB应用在压力下的承受能力。Siege支持身份验证、cookies、http、https和ftp协议。可以根据配置,对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的响应时间,并在一定数量的并发访问下重复进行。

siege可以从您选择的预置列表中请求随机的URL,所以siege可用于仿真用户请求负载,而ab则不能。但不要使用siege来执行最高性能基准调校测试,这方面ab就准确很多。

Siege支持多链接,支持get和post请求,可以对web系统进行多并发下持续请求的压力测试。

  • Siege官网:https://www.joedog.org/

  • Siege下载:http://download.joedog.org/siege/siege-latest.tar.gz

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

安装

解压并安装:

 1-- yum直接安装 2yum install -y siege 3 4-- 也可以编译安装 5tar -zxvf siege-latest.tar.gz 6cd siege-4.1.1 7./configure --with-ssl=/usr/local/openssl 8make && make install 91011[root@docker35 siege-4.1.1]# siege -h12New configuration template added to /root/.siege13Run siege -C to view the current settings in that file14SIEGE 4.1.115Usage: siege [options]16       siege [options] URL17       siege -g URL18Options:19  -V, --version             VERSION, prints the version number.20  -h, --help                HELP, prints this section.21  -C, --config              CONFIGURATION, show the current config.22  -v, --verbose             VERBOSE, prints notification to screen.23  -q, --quiet               QUIET turns verbose off and suppresses output.24  -g, --get                 GET, pull down HTTP headers and display the25                            transaction. Great for application debugging.26  -p, --print               PRINT, like GET only it prints the entire page.27  -c, --concurrent=NUM      CONCURRENT users, default is 1028  -r, --reps=NUM            REPS, number of times to run the test.29  -t, --time=NUMm           TIMED testing where "m" is modifier S, M, or H30                            ex: --time=1H, one hour test.31  -d, --delay=NUM           Time DELAY, random delay before each request32  -b, --benchmark           BENCHMARK: no delays between requests.33  -i, --internet            INTERNET user simulation, hits URLs randomly.34  -f, --file=FILE           FILE, select a specific URLS FILE.35  -R, --rc=FILE             RC, specify an siegerc file36  -l, --log[=FILE]          LOG to FILE. If FILE is not specified, the37                            default is used: PREFIX/var/siege.log38  -m, --mark="text"         MARK, mark the log file with a string.39                            between .001 and NUM. (NOT COUNTED IN STATS)40  -H, --header="text"       Add a header to request (can be many)41  -A, --user-agent="text"   Sets User-Agent in request42  -T, --content-type="text" Sets Content-Type in request43  -j, --json-output         JSON OUTPUT, print final stats to stdout as JSON44      --no-parser           NO PARSER, turn off the HTML page parser45      --no-follow           NO FOLLOW, do not follow HTTP redirects4647Copyright (C) 2021 by Jeffrey Fulmer, et al.48This is free software; see the source for copying conditions.49There is NO warranty; not even for MERCHANTABILITY or FITNESS50FOR A PARTICULAR PURPOSE.

参数详解:

  • -C,或--config 在屏幕上打印显示出当前的配置,配置是包括在配置文件$HOME/.siegerc
    中,可以编辑里面的参数,这样每次siege 都会按照它运行.

  • -v 运行时能看到详细的运行信息

  • -c n,或--concurrent=n 模拟有n个用户在同时访问,n不要设得太大,因为越大,siege 消耗本地机器的资源越多,并发用户数量,默认10个,注意:siege默认只支持255个并发数,可以自己自定义,修改/root/.siege/siege.conf
    下的limit数值。

  • -i,--internet 随机访问urls.txt中的url列表项,以此模拟真实的访问情况(随机性),当urls.txt存在时有效,模拟网络用户随机点击URL

  • -d n,--delay=n hit每个url之间的延迟,在0-n之间

  • -r n,--reps=n 重复运行测试n次,r和t不能同时使用

  • -t n,--time=n 持续运行siege ‘n’秒(如10S),分钟(10M),小时(10H)

  • -l 运行结束,将统计数据保存到日志文件中siege.log,一般位于/usr/local/var/siege.log
    中,也可在.siegerc
    中自定义

  • -R SIEGERC,--rc=SIEGERC 指定用特定的siege 配置文件来运行,默认的为$HOME/.siegerc

  • -f FILE, --file=FILE 指定用特定的urls文件运行siege ,默认为urls.txt,位于siege 安装目录下的etc/urls.txt

  • -V, --version    打印版本号

  • -h, --help    打印帮助信息

  • -g, --get    拉取http头信息

  • -p, --print    打印整个页面的内容

  • -b, --benchmark    请求没有延迟

  • -H, --header="text"    给请求添加头,支持多个

  • -A, --user-agent="text"    给请求设置User-Agent

  • -T, --content-type="text"    给请求设置Content-Type

性能参数

参数描述
Transactions命中次数
Availability命中率
Elapsed time整个压测花费的时间,从第一个开始到最后一个结束
Data transferred整个压测数据传输的总和
Response time响应时间是响应每个模拟用户请求所花费的平均时间
Transaction rate事务速率是服务器每秒能够处理的平均事务数. 简而言之:事务除以经过的时间
Throughput吞吐量是从服务器到所有模拟用户每秒传输的平均字节数
Concurrency并发是同时连接的平均数,这是一个随服务器性能下降而上升的数字
Successful transactions成功事务次数
Failed transactions失败事务次数
Longest transaction最长事务时间
Shortest transaction最短事务时间

显示默认配置

 1[root@docker35 ~]# siege -C 2CURRENT  SIEGE  CONFIGURATION 3Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/4.1.1 4Edit the resource file to change the settings. 5---------------------------------------------- 6version:                        4.1.1 7verbose:                        true 8color:                          true 9quiet:                          false10debug:                          false11protocol:                       HTTP/1.112HTML parser:                    enabled13get method:                     HEAD14connection:                     close15concurrent users:               2516time to run:                    n/a17repetitions:                    n/a18socket timeout:                 3019cache enabled:                  false20accept-encoding:                gzip, deflate21delay:                          0.000 sec22internet simulation:            false23benchmark mode:                 false24failures until abort:           102425named URL:                      none26URLs file:                      /usr/local/etc/urls.txt27thread limit:                   50028logging:                        false29log file:                       /usr/local/var/log/siege.log30resource file:                  /root/.siege/siege.conf31timestamped output:             false32comma separated output:         false33allow redirects:                true34allow zero byte data:           true35allow chunked encoding:         true36upload unique files:            true37json output:                    false38no-follow:39 - ad.doubleclick.net40 - pagead2.googlesyndication.com41 - ads.pubsqrd.com42 - ib.adnxs.com43proxy auth:                     44www auth:                       

测试多个url

用法举例:

1siege -c 200 -t 10S -i -d 1 -f url.txt

说明:-c是并发量,-t是时间。url.txt就是一个文本文件,每行都是一个url,它会从里面随机访问的。

url.txt文件内容如下:

1https://www.xmmup.com/linuxchakanzuixiaohaoneicundejincheng.html2https://www.xmmup.com/changjiandelinuxcaozuoxitongneihecanshu.html3https://www.xmmup.com/4https://www.xmmup.com/neicunfenpeizhongdenuma.html5https://www.xmmup.com/linuxchakanzuixiaohaoneicundejincheng.html6https://www.xmmup.com/phpyouhuakuozhanopcache.html

结果说明:

  • Transactions: 30000 hits:完成30000次处理

  • Availability: 100.00 %:成功率

  • Elapsed time: 68.59 secs:总共使用时间

  • Data transferred: 817.76 MB:共数据传输 817.76 MB

  • Response time: 0.04 secs:响应时间,显示网络连接的速度

  • Transaction rate: 437.38 trans/sec:平均每秒完成 437.38 次处理

  • Throughput: 11.92 MB/sec:平均每秒传送数据

  • Concurrency: 17.53:实际最高并发连接数

  • Successful transactions: 30000:成功处理次数

  • Failed transactions: 0:失败处理次数

  • Longest transaction: 3.12:每次传输所花最长时间

  • Shortest transaction: 0.00:每次传输所花最短时间

压测单个网址

1siege -c 1000 -t 10S https://www.xmmup.com

获取指定URL的Header信息,并显示HTTP处理信息

1siege -g https://www.xmmup.com

其它测试

  • 在urls.txt中列出所有的网址

1siege -c 200 -r 100 -f urls.txt
  • 随机选取urls.txt中列出所有的网址

1siege -c 200 -r 100 -f urls.txt -i
  • delay=0,更准确的压力测试,而不是功能测试

1siege -c 200 -r 100 -f urls.txt -i -b
  • 支持application/json方式请求

1siege -c1 -r1 "http://192.168.16.101:6005/bpm/processInstances/review PUT <./1.json"
  • 支持多个Header参数

1siege -c10 -r1 -p --header="Authorization: Bearer b7c75bae-9d68-4a74-bffb-95eb08a40918" --header="sg: 123456"
  • 指定http请求头文档类型

1siege -H "Content-Type:application/json" -c 200 -r 100 -f urls.txt -i -b

• 个人博客地址:www.xmmup.com

• 微信公众号:DB宝,作者:小麦苗,作者微信:db_bao

• 作者QQ:646634621,QQ群:230161599、618766405
• 提供Oracle OCP、OCM、高可用(rac+dg+ogg)、MySQL DBA和PostgreSQL DBA培训及其考证事宜
• 版权所有,欢迎分享本文,转载请保留出处

• 若有侵权请联系小麦苗删除

长按下图识别二维码,关注小麦苗的微信公众号:DB宝,学习最实用的数据库技术。

文章转载自DB宝,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论