siege简介
Siege是一款不错的网站压力测试工具,它可以非常容易地定制并发访问人数以及并发时间.
其安装、使用也非常方便,当然它是在Linux类环境下使用的,下面来对它作一个介绍。
安装
在mac上,可以使用brew来直接安装。
$ brew install siege
$ siege –help
SIEGE 3.1.3
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
-i, --internet INTERNET user simulation, hits URLs randomly.
-b, --benchmark BENCHMARK: no delays between requests.
-t, --time=NUMm TIMED testing where "m" is modifier S, M, or H
ex: --time=1H, one hour test.
-r, --reps=NUM REPS, number of times to run the test.
-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.
-d, --delay=NUM Time DELAY, random delay before each requst
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) 2015 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.
要使用最新的版本,去官网下载最新的源码进行build。
官方网址:http://www.joedog.org/
下载最新的版本源码,目前最新版本4.0.2,解压后,进入目录,执行:
$ ./configure
$ make
$ make install
完成后,siege执行文件被拷贝到/usr/local/bin/下。
执行一下
$ siege --help
[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.
使用1
比如,狗厂的兄弟对某个url进行简单的http访问压测:
$ siege -c100 -t60s -b http://***.item.com/999888
并发测试完毕后,打印出结果信息:
Transactions: 337998 hits
Availability: 100.00 %
Elapsed time: 59.09 secs
Data transferred: 2021.07 MB
Response time: 0.03 secs
Transaction rate: 5720.05 trans/sec
Throughput: 34.20 MB/sec
Concurrency: 149.79
Successful transactions: 337998
Failed transactions: 0
Longest transaction: 1.07
Shortest transaction: 0.00
$ siege -c600 -t60s -b http://***.item.jd.com/981821
并发测试完毕后,打印出结果信息:
Transactions: 370985 hits
Availability: 100.00 %
Elapsed time: 59.16 secs
Data transferred: 2218.32 MB
Response time: 0.10 secs
Transaction rate: 6270.88 trans/sec
Throughput: 37.50 MB/sec
Concurrency: 598.31
Successful transactions: 370985
Failed transactions: 0
Longest transaction: 1.32
Shortest transaction: 0.00
如果在并发的过程中,被访问的页面打开出错或及其缓慢,表示在当前并发条件下,被访问网站是不能承受的,也就是抗并发能力弱。
另外,在并发的过程中最好通过top命令来查看CPU和Memory的占用情况。
使用2: 对多个页面进行并发访问
新建一个文件,命名为urls,里面的内容为(只是例子,任何url都可以):
http://www.taobao.com
http://www.taobao.com/2010/12/16/2821/
http://www.taobao.com/2010/12/14/2806/
执行命令:
$ siege -f urls -c200 -t5
表示启动200个用户在5分钟内并发访问以上的url网址。
并发测试完毕后,打印出结果信息:
Lifting the server siege… done.
Transactions: 7555 hits
Availability: 99.47 %
Elapsed time: 299.92 secs
Data transferred: 99.17 MB
Response time: 7.30 secs
Transaction rate: 25.19 trans/sec
Throughput: 0.33 MB/sec
Concurrency: 183.84
Successful transactions: 7555
Failed transactions: 40
Longest transaction: 17.94
Shortest transaction: 0.02
使用siege 3.#版本进行http post
在使用http post方式时,结合http body类型。
siege -T ‘application/json’ -c 500 -r 1 ‘http://some.url./post-service/ POST <./postfile’
服务器端接收到body为postfile文件内容,但是content_type依旧是默认值“application/x-www-form-urlencoded”,致使服务器端不能正确处理。
将postfile文件名修改为postfile.json
siege -c 500 -r 1 ‘http://some.url./post-service/ POST <./postfile.json’
content_type被正确设置为application/json,服务器正常处理返回。
原来siege只能通过文件的扩展名来确定content type格式
对比apache的ab命令
该工具比较好用,没出现什么问题,一条命令搞定:
ab -n 5000 -c 500 -p postfile -T ‘application/json’ ‘http://some.url./post-service/’
ab 命令help
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header to use for POST/PUT data, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. 'Apache=1234'. (repeatable)
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-q Do not show progress when doing more than 150 requests
-l Accept variable document length (use this for dynamic pages)
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-r Don't exit on socket receive errors.
-m method Method name
-h Display usage information (this message)
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)