~/Downloads/siege-4.0.4$ ./configure
~/Downloads/siege-4.0.4$ make
~/Downloads/siege-4.0.4$ make install
注意:如果你不是root用户,需要sudo
~/Downloads/siege-4.0.4$ sudo make install
~/Downloads/siege-4.0.4$ siege -version
siege: invalid option -- 'e'
New configuration template added to /home/xxx/.siege
Run siege -C to view the current settings in that file
siege: invalid option -- 'e'
SIEGE 4.0.4
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 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
--no-parser NO PARSER, turn off the HTML page parser
--no-follow NO FOLLOW, do not follow HTTP redirects
Copyright (C) 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.
二、示例分析
1、模拟客户端okhttp连接池中只有一个连接复用的场景
测试目标:连接复用是否会请求超时,连接的存活时间长短和局域网网络设备参数配置,它们对客户端程序的影响大小。
image.png
~/Downloads/siege-4.0.4$ siege -d 180 -r 2 -c 1 -v
Transactions: 2 hits
Availability: 100.00 %
Elapsed time: 212.05 secs 测试耗时
Data transferred: 0.02 MB 数据传输量
Response time: 0.02 secs 平均响应时间
Transaction rate: 0.01 trans/sec 每秒事务处理量
Throughput: 0.00 MB/sec 吞吐率
Concurrency: 0.00 并发用户数
Successful transactions: 2
Failed transactions: 0
Longest transaction: 0.03 最长响应时间
Shortest transaction: 0.02 最短响应时间
如果上述第二次请求出现超时,如下所示
image.png
就需要进一步跟踪局域网的中间设备的配置参数了。
下面给出华为AR2200路由器,tcp和http协议的默认超时时间。
image.png
注意到tcp连接超时时间为600秒,但是http的超时时间为120秒,小于siege的delay 时间,从而导致第二次的请求超时。
image.png
这里补充下android客户端关于okhttp的连接池的默认值:
keepalive为5分钟,也即300秒。连接复用技术,如果一个连接是空闲状态,且存活期内,那么客户端将复用该http连接。
2、随机选取testUrls.txt中的网址,进行压力测试。
// -b,更准确的压力测试,而不是功能测试
siege -c 1000 -r 50 -f testUrls.txt -i -b