日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

web压力测试之siege

發布時間:2023/12/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 web压力测试之siege 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

siege簡介

Siege是一款不錯的網站壓力測試工具,它可以非常容易地定制并發訪問人數以及并發時間.
其安裝、使用也非常方便,當然它是在Linux類環境下使用的,下面來對它作一個介紹。

安裝

在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,解壓后,進入目錄,執行:

$ ./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] 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-r, --reps=NUM REPS, number of times to run the test.-t, --time=NUMm TIMED testing where "m" is modifier S, M, or Hex: --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, thedefault 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 requestCopyright (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)

總結

以上是生活随笔為你收集整理的web压力测试之siege的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。