Web性能测试工具Siege参数详解 & 示例

2020-04-22 15:16:11 浏览数 (1)

在上一篇博文【CentOS上安装Web性能测试工具Siege & 示例】中,给出了CentOS上安装Web性能测试工具Siege的步骤,并给出了一个简单的示例,如

示例 ==> 并发请求指定URL http://download.joedog.org/ siege -c 5 -r 2 http://download.joedog.org/ 参数说明-c 是并发量并发数为5, -r 是重复次数 重复2次

某次运行的结果~

代码语言:javascript复制
Transactions:		          30 hits        ## 完成处理数30
Availability:		      100.00 %           ## 可用,成功率100%
Elapsed time:		        4.67 secs        ## 耗时4.67秒
Data transferred:	        0.07 MB          ## 数据传输0.07MB
Response time:		        0.50 secs        ## 响应时间0.50秒
Transaction rate:	        6.42 trans/sec   ## 每秒完成6.42个处理
Throughput:		        0.01 MB/sec          ## 吞吐量,每秒传输0.01MB
Concurrency:		        3.21             ## 实际最高并发连接数
Successful transactions:          30         ## 成功完成处理30次
Failed transactions:	           0         ## 失败0次
Longest transaction:	        2.25         ## 每次传输所花最长时间
Shortest transaction:	        0.37         ## 每次传输所花最短时间

在本篇博文中,我们将对Siege使用方法和参数,结合示例进行说明。

Siege使用方法

可以先通过siege -h或者siege --help 命令,查看一下siege的帮助信息,如:

代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -h[alert] Zip encoding disabled; siege requires zlib support to enable itSIEGE 4.0.2Usage: siege [options]       siege [options] URL       siege -g URLOptions:  -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
Copyright (C) 2016 by Jeffrey Fulmer, et al.This is free software; see the source for copying conditions.There is NO warranty; not even for MERCHANTABILITY or FITNESSFOR A PARTICULAR PURPOSE.
[root@test03 siege-4.0.2]#

从上述帮助信息中,可以看出siege的使用方法有如下三种方法

Usage:

  1. siege [options]
  2. siege [options] URL
  3. siege -g URL

其中option的可选项有如下这些:

代码语言:javascript复制
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 [options]

该使用方法主要用于:

  • 查看版本信息
  • 查看帮助信息
  • 查看当前配置信息
  • 使用siege -V 或者 siege --version 查看siege版本信息
代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -V[alert] Zip encoding disabled; siege requires zlib support to enable itSIEGE 4.0.2
Copyright (C) 2016 by Jeffrey Fulmer, et al.This is free software; see the source for copying conditions.There is NO warranty; not even for MERCHANTABILITY or FITNESSFOR A PARTICULAR PURPOSE.
[root@test03 siege-4.0.2]#
  • 使用siege -h 或者 siege --help 查看帮助信息
代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -h[alert] Zip encoding disabled; siege requires zlib support to enable itSIEGE 4.0.2Usage: siege [options]       siege [options] URL       siege -g URLOptions:  -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
Copyright (C) 2016 by Jeffrey Fulmer, et al.This is free software; see the source for copying conditions.There is NO warranty; not even for MERCHANTABILITY or FITNESSFOR A PARTICULAR PURPOSE.
[root@test03 siege-4.0.2]#
  • 使用siege -C 或者 siege --config 查看当前Siege的配置信息
代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -C[alert] Zip encoding disabled; siege requires zlib support to enable itCURRENT  SIEGE  CONFIGURATIONMozilla/5.0 (unknown-x86_64-linux-gnu) Siege/4.0.2Edit the resource file to change the settings.----------------------------------------------version:                        4.0.2verbose:                        truecolor:                          truequiet:                          falsedebug:                          falseprotocol:                       HTTP/1.1HTML parser:                    enabledget method:                     HEADconnection:                     closeconcurrent users:               25time to run:                    n/arepetitions:                    n/asocket timeout:                 30accept-encoding:                *delay:                          0.500 secinternet simulation:            falsebenchmark mode:                 falsefailures until abort:           1024named URL:                      noneURLs file:                      /usr/local/etc/urls.txtthread limit:                   255logging:                        falselog file:                       /usr/local/var/log/siege.logresource file:                  /root/.siege/siege.conftimestamped output:             falsecomma separated output:         falseallow redirects:                trueallow zero byte data:           trueallow chunked encoding:         trueupload unique files:            trueno-follow: - ad.doubleclick.net - pagead2.googlesyndication.com - ads.pubsqrd.com - ib.adnxs.com
[root@test03 siege-4.0.2]#

siege -g URL

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

siege -g http://www.baidu.com

代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -g http://www.baidu.com[alert] Zip encoding disabled; siege requires zlib support to enable itHEAD / HTTP/1.0Host: www.baidu.comAccept: */*User-Agent: Mozilla/5.0 (unknown-x86_64-linux-gnu) Siege/4.0.2Connection: close

HTTP/1.1 200 OKServer: bfe/1.0.8.18Date: Sat, 03 Jun 2017 03:02:23 GMTContent-Type: text/htmlContent-Length: 277Last-Modified: Mon, 13 Jun 2016 02:50:23 GMTConnection: CloseETag: "575e1f6f-115"Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transformPragma: no-cacheAccept-Ranges: bytes


Transactions:               1 hitsAvailability:          100.00 %Elapsed time:            0.45 secsData transferred:          0.00 MBResponse time:            0.10 secsTransaction rate:          2.22 trans/secThroughput:            0.00 MB/secConcurrency:            0.22Successful transactions:           1Failed transactions:             0Longest transaction:          0.10Shortest transaction:          0.10
[root@test03 siege-4.0.2]#

siege [options] URL

这种使用方法是最主要的,接下来,结合示例对参数的使用进行说明。

Siege参数说明&示例

Siege常用参数

代码语言:javascript复制
Siege常用的参数有如下几个:

-c 或者 --concurrent=NUM : 用于指定并发人数
-r 或者 --reps=NUM       : 用于指定重复次数
-d 或者 --delay=NUM      : 用于指定延迟时间
-f 或者 --file=FILE      : 用于指定URL列表的文件,可以一次对多个路径进行测试
-t 或者 --time=NUMm      : 用于指定测试持续时间。例如:-t10S (10秒)  -t5M(5分钟)  -t1H(1小时)
-l 或者 --log[=FILE]     : 用于记录结果日志

一般测试基本上多个参数组合在一起来完成的,下面,我们就一起来玩几个测试示例~

并发请求URL

siege -c5 -r2 http://www.bing.com

代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -c5 -r2 http://www.bing.com[alert] Zip encoding disabled; siege requires zlib support to enable it** SIEGE 4.0.2** Preparing 5 concurrent users for battle.The server is now under siege...HTTP/1.1 301     0.13 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.27 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.32 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.37 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.43 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.50 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.22 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.17 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.12 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.05 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.24 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.28 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.30 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.34 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.22 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.16 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.11 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.34 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.png
Transactions:              30 hitsAvailability:          100.00 %Elapsed time:            1.73 secsData transferred:          1.27 MBResponse time:            0.19 secsTransaction rate:         17.34 trans/secThroughput:            0.73 MB/secConcurrency:            3.27Successful transactions:          30Failed transactions:             0Longest transaction:          0.50Shortest transaction:          0.05
[root@test03 siege-4.0.2]#

在此基础上增加持续时间,设置为5秒

siege -c5 -r2 -t5S http://www.bing.com

代码语言:javascript复制
/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释 
* [root@test03 siege-4.0.2]# siege -c5 -r2 -t5S http://www.bing.com[alert] Zip encoding disabled; siege requires zlib support to enable it[error] CONFIG conflict: selected time and repetition based testingdefaulting to time-based testing: 5 seconds** SIEGE 4.0.2** Preparing 5 concurrent users for battle.The server is now under siege...HTTP/1.1 301     0.13 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.14 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.19 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.32 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.36 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.42 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.23 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.17 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.11 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.22 secs:  126124 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.05 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.05 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.28 secs:  126124 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.45 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.49 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.35 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.52 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.15 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.10 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.28 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.08 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.23 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.18 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.13 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.29 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.05 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.05 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.28 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.31 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.31 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.34 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.38 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.24 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.18 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.13 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.05 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.24 secs:  126124 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.05 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.24 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.29 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.30 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.22 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.11 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.18 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.35 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.05 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.05 secs:       0 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.27 secs:  126124 bytes ==> GET  /HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  126124 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.23 secs:  126124 bytes ==> GET  /HTTP/1.1 301     0.06 secs:       0 bytes ==> GET  /HTTP/1.1 200     0.24 secs:  126124 bytes ==> GET  /
*/
Lifting the server siege...Transactions:              91 hitsAvailability:          100.00 %Elapsed time:            4.51 secsData transferred:          3.92 MBResponse time:            0.17 secsTransaction rate:         20.18 trans/secThroughput:            0.87 MB/secConcurrency:            3.36Successful transactions:          93Failed transactions:             0Longest transaction:          0.52Shortest transaction:          0.05
[root@test03 siege-4.0.2]#

多个URL场景测试

问题:如果想测试多个URL怎么办呢?

我们只要将多个URL存放到一个文件中即可~

通过siege -C我们可以看到如下信息:

代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -C[alert] Zip encoding disabled; siege requires zlib support to enable itCURRENT  SIEGE  CONFIGURATIONMozilla/5.0 (unknown-x86_64-linux-gnu) Siege/4.0.2Edit the resource file to change the settings.----------------------------------------------version:                        4.0.2verbose:                        truecolor:                          truequiet:                          falsedebug:                          falseprotocol:                       HTTP/1.1HTML parser:                    enabledget method:                     HEADconnection:                     closeconcurrent users:               25time to run:                    n/arepetitions:                    n/asocket timeout:                 30accept-encoding:                *delay:                          0.500 secinternet simulation:            falsebenchmark mode:                 falsefailures until abort:           1024named URL:                      noneURLs file:                      /usr/local/etc/urls.txtthread limit:                   255logging:                        falselog file:                       /usr/local/var/log/siege.logresource file:                  /root/.siege/siege.conftimestamped output:             falsecomma separated output:         falseallow redirects:                trueallow zero byte data:           trueallow chunked encoding:         trueupload unique files:            trueno-follow: - ad.doubleclick.net - pagead2.googlesyndication.com - ads.pubsqrd.com - ib.adnxs.com
[root@test03 siege-4.0.2]#

从上述信息中可以看出,Siege默认情况下URLS FILE的路径为/usr/local/etc/urls.txt

urls.txt的内容如下:

代码语言:javascript复制
# URLS file for siege
# --
# Format the url entries in any of the following formats:
# http://www.whoohoo.com/index.html
# http://www/index.html
# www/index.html
# http://www.whoohoo.com/cgi-bin/howto/display.cgi?1013
# Use the POST directive for pages that require it:
# http://www.whoohoo.com/cgi-bin/haha.cgi POST ha=1&ho=2
#      or POST content from a file:
# http://www.whoohoo.com/melvin.jsp POST </home/jeff/haha
# http://www.whoohoo.com/melvin.jsp POST <./haha
# You may also set and reference variables inside this file,
# for more information, man urls_txt
# -------------------------------------------------------

我们可以通过 -f参数来指定一个文件,如/srv/myurls.txt, 里面存放指定网址

代码语言:javascript复制
http://www.baidu.com
http://cn.bing.com/

注,上述URL很简单,并不在Header或者其他地方设置参数

使用如下命令即可~

siege -c5 -r2 -f /srv/myurls.txt

代码语言:javascript复制
[root@test03 siege-4.0.2]# siege -c5 -r2 -f /srv/myurls.txt [alert] Zip encoding disabled; siege requires zlib support to enable it** SIEGE 4.0.2** Preparing 5 concurrent users for battle.The server is now under siege...HTTP/1.1 200     0.14 secs:  102074 bytes ==> GET  /HTTP/1.1 200     0.16 secs:  102202 bytes ==> GET  /HTTP/1.1 200     0.19 secs:  102123 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  102238 bytes ==> GET  /HTTP/1.1 200     0.14 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.12 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.09 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.28 secs:  102168 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.05 secs:      91 bytes ==> GET  /img/gs.gif[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connectedHTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.07 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.07 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.28 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.28 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.30 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.17 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.10 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.32 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.23 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.png
Transactions:              40 hitsAvailability:           88.89 %Elapsed time:            1.62 secsData transferred:          1.62 MBResponse time:            0.11 secsTransaction rate:         24.69 trans/secThroughput:            1.00 MB/secConcurrency:            2.81Successful transactions:          40Failed transactions:             5Longest transaction:          0.32Shortest transaction:          0.05
[root@test03 siege-4.0.2]#

记录结果到日志

如果想把测试结果存放到日志文件中去,可以使用--log参数,如:

siege -c5 -r2 --log=/srv/siege_result.log -f /srv/myurls.txt

代码语言:javascript复制
[root@test03 srv]# siege -c5 -r2 --log=/srv/siege_result.log  -f /srv/myurls.txt[alert] Zip encoding disabled; siege requires zlib support to enable it** SIEGE 4.0.2** Preparing 5 concurrent users for battle.The server is now under siege...HTTP/1.1 200     0.15 secs:  102110 bytes ==> GET  /HTTP/1.1 200     0.20 secs:  102087 bytes ==> GET  /HTTP/1.1 200     0.24 secs:  101920 bytes ==> GET  /HTTP/1.1 200     0.27 secs:  102186 bytes ==> GET  /HTTP/1.1 200     0.15 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.09 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.30 secs:  101935 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscriptHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.07 secs:      91 bytes ==> GET  /img/gs.gifHTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connected[error] HTTPS requires libssl: Unable to reach ss1.bdstatic.com with this protocol: Transport endpoint is already connectedHTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.07 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.jsHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.07 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gifHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.07 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.pngHTTP/1.1 200     0.26 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.29 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.12 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.30 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.25 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.25 secs:  126193 bytes ==> GET  /HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.pngHTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms answers Homepage ZhCn$BingAppQR/ic/0d08e928/0f482622.png
Transactions:              40 hitsAvailability:           88.89 %Elapsed time:            1.70 secsData transferred:          1.62 MBResponse time:            0.11 secsTransaction rate:         23.53 trans/secThroughput:            0.95 MB/secConcurrency:            2.66Successful transactions:          40Failed transactions:             5Longest transaction:          0.30Shortest transaction:          0.05
LOG FILE: /srv/siege_result.logYou can disable this log file notification by editing/root/.siege/siege.conf and changing 'show-logfile' to false.[root@test03 srv]#

其中,

代码语言:javascript复制
Transactions:		          40 hits
Availability:		       88.89 %
Elapsed time:		        1.70 secs
Data transferred:	        1.62 MB
Response time:		        0.11 secs
Transaction rate:	       23.53 trans/sec
Throughput:		        0.95 MB/sec
Concurrency:		        2.66
Successful transactions:          40
Failed transactions:	           5
Longest transaction:	        0.30
Shortest transaction:	        0.05

这些结果信息会记录到指定的siege_result.log文件中,

代码语言:javascript复制
  Date & Time,  Trans,  Elap Time,  Data Trans,  Resp Time,  Trans Rate,  Throughput,  Concurrent,    OKAY,   Failed2017-06-03 14:37:03,     40,       1.70,           1,       0.11,       23.53,        0.59,        2.66,      40,       5

Header参数传值

在平时写接口的时候,可能需要先通过一个key获得相应的token,在这种时候,获取token的接口,需要在Header中设置key的参数和值。

在这种情况下,可以通过--header "key:abcdefg123456789" 这样的方法来进行测试,如:

代码语言:javascript复制
 siege -c5 -r2 --header "key:WJPRVEZEPMGX4RYESQ4ZPYPQLP2G0HCA" http://127.0.0.1:8080/accessToken

测试示例:

代码语言:javascript复制
[root@test03 srv]#  siege -c5 -r2 --header "key:WJPRVEZEPMGX4RYESQ4ZPYPQLP2G0HCA" http://127.0.0.1:8080/accessToken[alert] Zip encoding disabled; siege requires zlib support to enable it** SIEGE 4.0.2** Preparing 5 concurrent users for battle.The server is now under siege...HTTP/1.1 200     0.06 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.06 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.08 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.09 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.09 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessTokenHTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessToken
Transactions:              10 hitsAvailability:          100.00 %Elapsed time:            0.77 secsData transferred:          0.00 MBResponse time:            0.05 secsTransaction rate:         12.99 trans/secThroughput:            0.00 MB/secConcurrency:            0.62Successful transactions:          10Failed transactions:             0Longest transaction:          0.09Shortest transaction:          0.02
[root@test03 srv]#

POST JSON测试

假设我们需要测试一个接口方法,POST请求,请求内容为JSON, 并且需要在Header中使用AccessToken。

问题: 这样的情况,我们如何进行传值和测试呢?

Header中的传值可以使用--header "accessToken:c6fe5634d629497ba1bb9e89c2e2fb59"来完成。

至于提交的JSON内容,可以将其放到一个文件中( 如myjson.txt ), 本示例文件中的内容如下:

代码语言:javascript复制
{
        "actions":[{
                "actionId":"set_room_temp",
                "value":28
        }]
}

然后指定URL路径 和 json体的文件路径

'http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000POST < /srv/myjson.txt'

注意: 上述内容需要用单引号括起来,否则会产生错误~

本文使用的示例如下:

siege -c5 -r1 --header "accessToken:c6fe5634d629497ba1bb9e89c2e2fb59" 'http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000 POST < /srv/myjson.txt'

代码语言:javascript复制
[root@test03 srv]# siege -c5 -r1 --header "accessToken:c6fe5634d629497ba1bb9e89c2e2fb59" 'http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000 POST < /srv/myjson.txt'[alert] Zip encoding disabled; siege requires zlib support to enable it** SIEGE 4.0.2** Preparing 5 concurrent users for battle.The server is now under siege...HTTP/1.1 200     0.13 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000HTTP/1.1 200     0.13 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000HTTP/1.1 200     0.14 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000HTTP/1.1 200     0.15 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000HTTP/1.1 200     0.16 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000
Transactions:               5 hitsAvailability:          100.00 %Elapsed time:            0.54 secsData transferred:          0.00 MBResponse time:            0.14 secsTransaction rate:          9.26 trans/secThroughput:            0.00 MB/secConcurrency:            1.31Successful transactions:           5Failed transactions:             0Longest transaction:          0.16Shortest transaction:          0.13
[root@test03 srv]#

小结

通过上述的介绍,Siege常用的参数和使用示例基本上写完了。

有兴趣的读者,可以到Siege官网【https://www.joedog.org/siege-manual/】上去查看更多的资料。

0 人点赞