每日一博|Web 性能测试工具 Siege 参数详解

栏目: 编程工具 · 发布时间: 7年前

内容简介:每日一博|Web 性能测试工具 Siege 参数详解

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

示例 ==> 并发请求指定URL http://download.joedog.org/

siege -c 5 -r 2 http://download.joedog.org/

参数说明:  -c 是并发量 并发数为5,  -r 是重复次数  重复2次

某次运行的结果~

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的帮助信息,如:

[root@test03 siege-4.0.2]# siege -h
[alert] Zip encoding disabled; siege requires zlib support to enable it
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

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 FITNESS
FOR A PARTICULAR PURPOSE.

[root@test03 siege-4.0.2]#

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

Usage:

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

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

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版本信息
[root@test03 siege-4.0.2]# siege -V
[alert] Zip encoding disabled; siege requires zlib support to enable it
SIEGE 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 FITNESS
FOR A PARTICULAR PURPOSE.

[root@test03 siege-4.0.2]#
  • 使用 siege -h 或者 siege --help 查看帮助信息
[root@test03 siege-4.0.2]# siege -h
[alert] Zip encoding disabled; siege requires zlib support to enable it
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

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 FITNESS
FOR A PARTICULAR PURPOSE.

[root@test03 siege-4.0.2]#
  • 使用 siege -C  或者 siege --config  查看当前Siege的配置信息
[root@test03 siege-4.0.2]# siege -C
[alert] Zip encoding disabled; siege requires zlib support to enable it
CURRENT  SIEGE  CONFIGURATION
Mozilla/5.0 (unknown-x86_64-linux-gnu) Siege/4.0.2
Edit the resource file to change the settings.
----------------------------------------------
version:                        4.0.2
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
accept-encoding:                *
delay:                          0.500 sec
internet simulation:            false
benchmark mode:                 false
failures until abort:           1024
named URL:                      none
URLs file:                      /usr/local/etc/urls.txt
thread limit:                   255
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
no-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

[root@test03 siege-4.0.2]# siege -g http://www.baidu.com
[alert] Zip encoding disabled; siege requires zlib support to enable it
HEAD / HTTP/1.0
Host: www.baidu.com
Accept: */*
User-Agent: Mozilla/5.0 (unknown-x86_64-linux-gnu) Siege/4.0.2
Connection: close


HTTP/1.1 200 OK
Server: bfe/1.0.8.18
Date: Sat, 03 Jun 2017 03:02:23 GMT
Content-Type: text/html
Content-Length: 277
Last-Modified: Mon, 13 Jun 2016 02:50:23 GMT
Connection: Close
ETag: "575e1f6f-115"
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Pragma: no-cache
Accept-Ranges: bytes



Transactions:		           1 hits
Availability:		      100.00 %
Elapsed time:		        0.45 secs
Data transferred:	        0.00 MB
Response time:		        0.10 secs
Transaction rate:	        2.22 trans/sec
Throughput:		        0.00 MB/sec
Concurrency:		        0.22
Successful transactions:           1
Failed transactions:	           0
Longest transaction:	        0.10
Shortest transaction:	        0.10
 
[root@test03 siege-4.0.2]#

siege [options] URL

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

Siege参数说明&示例

Siege常用参数

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

每日一博|Web 性能测试工具 Siege 参数详解

[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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.17 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.12 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.16 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.11 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.34 secs:  126124 bytes ==> GET  /
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png

Transactions:		          30 hits
Availability:		      100.00 %
Elapsed time:		        1.73 secs
Data transferred:	        1.27 MB
Response time:		        0.19 secs
Transaction rate:	       17.34 trans/sec
Throughput:		        0.73 MB/sec
Concurrency:		        3.27
Successful transactions:          30
Failed transactions:	           0
Longest transaction:	        0.50
Shortest transaction:	        0.05
 
[root@test03 siege-4.0.2]#

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

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

[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 testing
defaulting 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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.17 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.11 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
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.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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.52 secs:  126124 bytes ==> GET  /
HTTP/1.1 200     0.15 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.10 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.28 secs:  126124 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.13 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.29 secs:  126124 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.18 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.13 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.11 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.18 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.35 secs:  126124 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.05 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 301     0.07 secs:       0 bytes ==> GET  /
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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 hits
Availability:		      100.00 %
Elapsed time:		        4.51 secs
Data transferred:	        3.92 MB
Response time:		        0.17 secs
Transaction rate:	       20.18 trans/sec
Throughput:		        0.87 MB/sec
Concurrency:		        3.36
Successful transactions:          93
Failed transactions:	           0
Longest transaction:	        0.52
Shortest transaction:	        0.05
 
[root@test03 siege-4.0.2]#

多个URL场景测试

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

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

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

[root@test03 siege-4.0.2]# siege -C
[alert] Zip encoding disabled; siege requires zlib support to enable it
CURRENT  SIEGE  CONFIGURATION
Mozilla/5.0 (unknown-x86_64-linux-gnu) Siege/4.0.2
Edit the resource file to change the settings.
----------------------------------------------
version:                        4.0.2
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
accept-encoding:                *
delay:                          0.500 sec
internet simulation:            false
benchmark mode:                 false
failures until abort:           1024
named URL:                      none
URLs file:                      /usr/local/etc/urls.txt
thread limit:                   255
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
no-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的内容如下:

# 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, 里面存放指定网址

http://www.baidu.com
http://cn.bing.com/

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

使用如下命令即可~

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

[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=noscript
HTTP/1.1 200     0.12 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.09 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.28 secs:  102168 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/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 connected
HTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.07 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.07 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.10 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.32 secs:  126193 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.23 secs:  126193 bytes ==> GET  /
HTTP/1.1 200     0.07 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png

Transactions:		          40 hits
Availability:		       88.89 %
Elapsed time:		        1.62 secs
Data transferred:	        1.62 MB
Response time:		        0.11 secs
Transaction rate:	       24.69 trans/sec
Throughput:		        1.00 MB/sec
Concurrency:		        2.81
Successful transactions:          40
Failed transactions:	           5
Longest transaction:	        0.32
Shortest transaction:	        0.05
 
[root@test03 siege-4.0.2]#

记录结果到日志

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

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

[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=noscript
HTTP/1.1 200     0.09 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.30 secs:  101935 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/1.1 200     0.06 secs:    2947 bytes ==> GET  /baidu.html?from=noscript
HTTP/1.1 200     0.06 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/1.1 200     0.07 secs:      91 bytes ==> GET  /img/gs.gif
HTTP/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 connected
HTTP/1.1 200     0.05 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.06 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.07 secs:   93750 bytes ==> GET  /r/www/cache/static/jquery/jquery-1.10.2.min_65682a2.js
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.07 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:     705 bytes ==> GET  /img/baidu_jgylogo3.gif
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.07 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/1.1 200     0.06 secs:    7877 bytes ==> GET  /img/bd_logo1.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.30 secs:  126193 bytes ==> GET  /
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/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%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png
HTTP/1.1 200     0.06 secs:    6752 bytes ==> GET  /rms/rms%20answers%20Homepage%20ZhCn$BingAppQR/ic/0d08e928/0f482622.png

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
 
LOG FILE: /srv/siege_result.log
You can disable this log file notification by editing
/root/.siege/siege.conf and changing 'show-logfile' to false.
[root@test03 srv]#

其中,

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 文件中,

Date & Time,  Trans,  Elap Time,  Data Trans,  Resp Time,  Trans Rate,  Throughput,  Concurrent,    OKAY,   Failed
2017-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" 这样的方法来进行测试~

如:

siege -c5 -r2 --header "key:WJPRVEZEPMGX4RYESQ4ZPYPQLP2G0HCA" http://127.0.0.1:8080/accessToken

测试示例:

[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  /accessToken
HTTP/1.1 200     0.06 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.08 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.09 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.09 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessToken
HTTP/1.1 200     0.02 secs:      99 bytes ==> GET  /accessToken

Transactions:		          10 hits
Availability:		      100.00 %
Elapsed time:		        0.77 secs
Data transferred:	        0.00 MB
Response time:		        0.05 secs
Transaction rate:	       12.99 trans/sec
Throughput:		        0.00 MB/sec
Concurrency:		        0.62
Successful transactions:          10
Failed transactions:	           0
Longest transaction:	        0.09
Shortest transaction:	        0.02
 
[root@test03 srv]#

POST + JSON测试

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

问题:

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

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

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

{
        "actions":[{
                "actionId":"set_room_temp",
                "value":28
        }]
}

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

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

注意:

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

本文使用的示例如下:

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

[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/3WIMLT4P3FZvirtualsn0000000
HTTP/1.1 200     0.13 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000
HTTP/1.1 200     0.14 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000
HTTP/1.1 200     0.15 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000
HTTP/1.1 200     0.16 secs:      57 bytes ==> POST http://127.0.0.1/v1/control/3WIMLT4P3FZvirtualsn0000000

Transactions:		           5 hits
Availability:		      100.00 %
Elapsed time:		        0.54 secs
Data transferred:	        0.00 MB
Response time:		        0.14 secs
Transaction rate:	        9.26 trans/sec
Throughput:		        0.00 MB/sec
Concurrency:		        1.31
Successful transactions:           5
Failed transactions:	           0
Longest transaction:	        0.16
Shortest transaction:	        0.13
 
[root@test03 srv]#

小结

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

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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

长尾理论

长尾理论

[美]克里斯•安德森 (Chris Anderson) / 乔江涛、石晓燕 / 中信出版社 / 2012 / 68.00元

网络经济正如火如荼地发展着,长尾理论无疑成为当代商务人士最为关注的焦点之一。不论是关于长尾理论的溢美还是论战,都代表了其备受关注的程度。 《长尾理论》是克里斯•安德森对这些争论的最明确的回答。在书中,他详细阐释了长尾的精华所在,指出商业和文化的未来不在于传统需求曲线上那个代表“畅销商品”的头部,而是那条代表“冷门商品”的经常被人遗忘的长尾。他还揭示了长尾现象是如何从工业资本主义原动力——规模......一起来看看 《长尾理论》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具