web压力测试之siege
siege簡介
Siege是一款不錯的網站壓力測試工具,它可以非常容易地定制并發(fā)訪問人數(shù)以及并發(fā)時間.
其安裝、使用也非常方便,當然它是在Linux類環(huán)境下使用的,下面來對它作一個介紹。
安裝
在mac上,可以使用brew來直接安裝。
$ brew install siege
$ siege –help
SIEGE 3.1.3 Usage: siege [options]siege [options] URLsiege -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 thetransaction. 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 Hex: --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, thedefault 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 requstbetween .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 requestCopyright (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,解壓后,進入目錄,執(zhí)行:
$ ./configure $ make $ make install完成后,siege執(zhí)行文件被拷貝到/usr/local/bin/下。
執(zhí)行一下
$ siege --help
使用1
比如,狗廠的兄弟對某個url進行簡單的http訪問壓測:
$ siege -c100 -t60s -b http://***.item.com/999888并發(fā)測試完畢后,打印出結果信息:
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
并發(fā)測試完畢后,打印出結果信息:
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
如果在并發(fā)的過程中,被訪問的頁面打開出錯或及其緩慢,表示在當前并發(fā)條件下,被訪問網站是不能承受的,也就是抗并發(fā)能力弱。
另外,在并發(fā)的過程中最好通過top命令來查看CPU和Memory的占用情況。
使用2: 對多個頁面進行并發(fā)訪問
新建一個文件,命名為urls,里面的內容為(只是例子,任何url都可以):
http://www.taobao.com http://www.taobao.com/2010/12/16/2821/ http://www.taobao.com/2010/12/14/2806/執(zhí)行命令:
$ siege -f urls -c200 -t5表示啟動200個用戶在5分鐘內并發(fā)訪問以上的url網址。
并發(fā)測試完畢后,打印出結果信息:
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命令
該工具比較好用,沒出現(xiàn)什么問題,一條命令搞定:
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)總結
以上是生活随笔為你收集整理的web压力测试之siege的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 智能游戏机
- 下一篇: JAVA Web Servlet中的异步