「前端」壓力測試工具ab、siege、webbench

概念

吞吐率(Requests per second)

每秒處理的請求數

併發連接數(The number of concurrent connections)

某個時刻同時存在的連接數。

併發用戶數(The number of concurrent users,Concurrency Level)

某個時刻同時存在的用戶數。一個用戶可能存在多個連接。譬如一個賬號不同瀏覽器登錄。

用戶平均請求等待時間

Time per request:指處理完成所有請求數所花費的時間 /(總請求數 / 併發用戶數);

服務器平均請求等待時間

Time per request:指處理完成所有請求數所花費的時間 /(總請求數 );

安裝

mac 自帶ab

存在的兩個問題aprpoll: The timeout specified has expired (70007)、aprsocket_recv: Connection reset by peer (xx),[請移步](https://yq.aliyun.com/articles/682791?spm=a2c4e.11153940.0.0.15747203SXQaVQ&type=2)

ab 
ab: wrong number of arguments
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)
-I Disable TLS Server Name Indication (SNI) extension
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(TLS1, TLS1.1, TLS1.2 or ALL)

常用參數說明

-n:總請求次數(最小默認為 1);
-c:併發次數(最小默認為 1 且不能大於總請求次數,例如:10 個請求,10 個併發,實際就是 1 人請求 1 次);
-p:post 參數文檔路徑(-p 和 -T 參數要配合使用);

-T:header 頭內容類型(此處切記是大寫英文字母 T)。

安裝siege

brew install siege

siege參數說明

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) 2017 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.

siege示例

siege -c 併發數 -t 運行測試時間 URL

webbench

//安裝依賴
brew install ctags
wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz 
// or http://www.ha97.com/code/webbench-1.5.tar.gz
tar -zxf webbench-1.5.tar.gz
cd webbench-1.5
sudo mkdir -pv /usr/local/man/man1
sudo make && sudo make install

webbench 參數說明

webbench [option]... URL
-f|--force Don't wait for reply from server.
-r|--reload Send reload request - Pragma: no-cache.
-t|--time Run benchmark for seconds. Default 30.
-p|--proxy <port> Use proxy server for request.
-c|--clients Run HTTP clients at once. Default one.
-9|--http09 Use HTTP/0.9 style requests.
-1|--http10 Use HTTP/1.0 protocol.
-2|--http11 Use HTTP/1.1 protocol.
--get Use GET request method.
--head Use HEAD request method.
--options Use OPTIONS request method.
--trace Use TRACE request method.
-?|-h|--help This information.
-V|--version Display program version.
/<port>

示例

webbench -c 併發數 -t 運行測試時間 URL

參考文獻

yq.aliyun.com/articles/130859

本文作者:前端首席體驗師(CheongHu)

聯繫郵箱:[email protected]


分享到:


相關文章: