用節點編寫的HTTP/1.1基準測試工具,其靈感來自WRK和WRK2,並支持HTTP管道和HTTPS。在我的盒子上, Autocannon比wrk和wrk2產生的負載更多,有關更多詳細信息,請參見限制。
安裝
用法
API
致謝
執照
npm i autocannon -g
或者如果要使用API或作為依賴性:
npm i autocannon --save
Usage: autocannon [opts] URL
URL is any valid HTTP or HTTPS URL.
If the PORT environment variable is set, the URL can be a path. In that case 'http://localhost:$PORT/path' will be used as the URL.
Available options:
-c/--connections NUM
The number of concurrent connections to use. default: 10.
-p/--pipelining NUM
The number of pipelined requests to use. default: 1.
-d/--duration SEC
The number of seconds to run the autocannon. default: 10.
-a/--amount NUM
The number of requests to make before exiting the benchmark. If set, duration is ignored.
-L NUM
The number of milliseconds to elapse between taking samples. This controls the sample interval, & therefore the total number of samples, which affects statistical analyses. default: 1.
-S/--socketPath
A path to a Unix Domain Socket or a Windows Named Pipe. A URL is still required to send the correct Host header and path.
-w/--workers
Number of worker threads to use to fire requests.
-W/--warmup
Use a warm up interval before starting sampling.
This enables startup processes to finish and traffic to normalize before sampling begins
use -c and -d sub args e.g. `--warmup [ -c 1 -d 3 ]`
--on-port
Start the command listed after -- on the command line. When it starts listening on a port,
start sending requests to that port. A URL is still required to send requests to
the correct path. The hostname can be omitted, `localhost` will be used by default.
If the command after -- is `node <script>`, this flag is optional and assumed to be `true`.
-m/--method METHOD
The HTTP method to use. default: 'GET'.
-t/--timeout NUM
The number of seconds before timing out and resetting a connection. default: 10
-T/--title TITLE
The title to place in the results for identification.
-b/--body BODY
The body of the request.
NOTE: This option needs to be used with the '-H/--headers' option in some frameworks
-F/--form FORM
Upload a form (multipart/form-data). The form options can be a JSON string like
'{ "field 1": { "type": "text", "value": "a text value"}, "field 2": { "type": "file", "path": "path to the file" } }'
or a path to a JSON file containing the form options.
When uploading a file the default filename value can be overridden by using the corresponding option:
'{ "field name": { "type": "file", "path": "path to the file", "options": { "filename": "myfilename" } } }'
Passing the filepath to the form can be done by using the corresponding option:
'{ "field name": { "type": "file", "path": "path to the file", "options": { "filepath": "/some/path/myfilename" } } }'
-i/--input FILE
The body of the request. See '-b/body' for more details.
-H/--headers K=V
The request headers.
--har FILE
When provided, Autocannon will use requests from the HAR file.
CAUTION: you have to specify one or more domains using URL option: only the HAR requests to the same domains will be considered.
NOTE: you can still add extra headers with -H/--headers but -m/--method, -F/--form, -i/--input -b/--body will be ignored.
-B/--bailout NUM
The number of failures before initiating a bailout.
-M/--maxConnectionRequests NUM
The max number of requests to make per connection to the server.
-O/--maxOverallRequests NUM
The max number of requests to make overall to the server.
-r/--connectionRate NUM
The max number of requests to make per second from an individual connection.
-R/--overallRate NUM
The max number of requests to make per second from all connections.
connection rate will take precedence if both are set.
NOTE: if using rate limiting and a very large rate is entered which cannot be met, Autocannon will do as many requests as possible per second.
Also, latency data will be corrected to compensate for the effects of the coordinated omission issue.
If you are not familiar with the coordinated omission issue, you should probably read [this article](http://highscalability.com/blog/2015/10/5/your-load-generator-is-probably-lying-to-you-take-the-red-pi.html) or watch this [Gil Tene's talk](https://www.youtube.com/watch?v=lJ8ydIuPFeU) on the topic.
-C/--ignoreCoordinatedOmission
Ignore the coordinated omission issue when requests should be sent at a fixed rate using 'connectionRate' or 'overallRate'.
NOTE: it is not recommended to enable this option.
When the request rate cannot be met because the server is too slow, many request latencies might be missing and Autocannon might report a misleading latency distribution.
-D/--reconnectRate NUM
The number of requests to make before resetting a connections connection to the
server.
-n/--no-progress
Don't render the progress bar. default: false.
-l/--latency
Print all the latency data. default: false.
-I/--idReplacement
Enable replacement of `[<id>]` with a randomly generated ID within the request body. e.g. `/items/[<id>]`. default: false.
-j/--json
Print the output as newline delimited JSON. This will cause the progress bar and results not to be rendered. default: false.
-f/--forever
Run the benchmark forever. Efficiently restarts the benchmark on completion. default: false.
-s/--servername
Server name for the SNI (Server Name Indication) TLS extension. Defaults to the hostname of the URL when it is not an IP address.
-x/--excludeErrorStats
Exclude error statistics (non-2xx HTTP responses) from the final latency and bytes per second averages. default: false.
-E/--expectBody EXPECTED
Ensure the body matches this value. If enabled, mismatches count towards bailout.
Enabling this option will slow down the load testing.
--renderStatusCodes
Print status codes and their respective statistics.
--cert
Path to cert chain in pem format
--key
Path to private key for specified cert in pem format
--ca
Path to trusted ca certificates for the test. This argument accepts both a single file as well as a list of files
--debug
Print connection errors to stderr.
-v/--version
Print the version number.
-V/--verbose
Print the table with results. default: true.
-h/--help
Print this menu.Autocannon在這樣的表中輸出數據:
Running 10s test @ http://localhost:3000 10 connections ┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬──────────┐ │ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │ ├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼──────────┤ │ Latency │ 0 ms │ 0 ms │ 0 ms │ 1 ms │ 0.02 ms │ 0.16 ms │ 16.45 ms │ └─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴──────────┘ ┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐ │ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │ ├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Req/Sec │ 20623 │ 20623 │ 25583 │ 26271 │ 25131.2 │ 1540.94 │ 20615 │ ├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Bytes/Sec │ 2.29 MB │ 2.29 MB │ 2.84 MB │ 2.92 MB │ 2.79 MB │ 171 kB │ 2.29 MB │ └───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘ Req/Bytes counts sampled once per second. 251k requests in 10.05s, 27.9 MB read
有兩個表:一個用於請求延遲,另一個用於請求卷。
延遲表列出了2.5%百分位數的請求時間,即快速離群值;中位數為50%;速度為97.5%,速度緩慢;佔99%,是最慢的異常值。在這裡,較低意味著更快。
請求卷表列出了發送的請求數和下載的字節數。這些值每秒採樣一次。較高的值意味著處理更多的請求。在上面的示例中,在最壞情況下(最慢1%)在1秒內下載了2.29 MB。由於我們只運行10秒,只有10個樣本,因此最小值和1%和2.5%的百分位數都是同一樣本。隨著時間的延長,這些數字會有所不同。
傳遞-l標誌時,第三個表列出了Autocannon記錄的所有延遲百分比:
┌────────────┬──────────────┐ │ Percentile │ Latency (ms) │ ├────────────┼──────────────┤ │ 0.001 │ 0 │ ├────────────┼──────────────┤ │ 0.01 │ 0 │ ├────────────┼──────────────┤ │ 0.1 │ 0 │ ├────────────┼──────────────┤ │ 1 │ 0 │ ├────────────┼──────────────┤ │ 2.5 │ 0 │ ├────────────┼──────────────┤ │ 10 │ 0 │ ├────────────┼──────────────┤ │ 25 │ 0 │ ├────────────┼──────────────┤ │ 50 │ 0 │ ├────────────┼──────────────┤ │ 75 │ 0 │ ├────────────┼──────────────┤ │ 90 │ 0 │ ├────────────┼──────────────┤ │ 97.5 │ 0 │ ├────────────┼──────────────┤ │ 99 │ 1 │ ├────────────┼──────────────┤ │ 99.9 │ 1 │ ├────────────┼──────────────┤ │ 99.99 │ 3 │ ├────────────┼──────────────┤ │ 99.999 │ 15 │ └────────────┴──────────────┘
如果發送了很多(數百萬)請求,這可以提供更多的見解。
'使用strict'Conconst autocannon = require('autocannon')autocannon({
URL:'http:// localhost:3000',,
連接:10,//默認值
管道:1,//默認
持續時間:10 //默認},console.log)// async/eakeaitAsync function foo(){
const結果=等待autocannon({url:'http:// localhost:3000',連接:10,// defaultPipelining:1,// defaultDuration:10 // default
}))
console.log(結果)}在工人模式下, autocannon使用Node的Worker類實例在多個線程中執行負載測試。
amount和connections參數分為工人。如果任何一個參數都不由workers數量排除,則每個工人的值舍入到最低整數,或設置為1 ,以較高者為準。所有其他參數均已應用於每個工作人員,就好像測試是單線程一樣。
注意:與amount和connections不同,每個工作人員都應用“總體”參數, maxOverallRequests和overallRate 。例如,如果將connections設置為4 ,則將workers設置為2 ,而maxOverallRequests將連接設置為10 ,則每個工人將收到2連接和一個10的maxOverallRequests ,導致發送20請求。
'使用strict'Conconst autocannon = require('autocannon')autocannon({
URL:'http:// localhost:3000',,
連接:10,//默認值
管道:1,//默認
持續時間:10,//默認
工人:4},console.log)注意:在工人模式下,您需要將絕對文件路徑傳遞給接受function的所有選項。這是因為傳遞到主過程的功能無法克隆並傳遞給工人。因此,它需要一個可能require文件。此行為的選項顯示在下面的示例中
'使用strict'Conconst autocannon = require('autocannon')autocannon({
// ...
工人:4,
setUpclient:'/full/path/to/setup-client.js',
verifybody:'/full/path/to/verify-body.js'
請求:[{// ... onResponse:'/full/path/to/on-response.js'},{// ... setuprequest:'/full/path/to/setup-request.js'}
]},console.log)啟動Autocannon以給定的目標。
opts :Autocannon實例的配置選項。這可以具有以下屬性。必需的。
body :在場時,將覆蓋opts.body 。選修的
headers :當下時,將覆蓋opts.headers 。選修的
method :當存在時,將覆蓋opts.method 。選修的
path :在場時,將覆蓋opts.path 。選修的
setupRequest :您可以提供的Function來突變原始request對象,例如request.method = 'GET' 。它採用request (對象)和context (對象)參數,並且必須返回修改後的請求。當它返回虛假值時,Autocannon將從第一個請求重新啟動。使用workers時,您需要提供默認導出功能的文件路徑(查看工人部分以獲取更多詳細信息)可選
onResponse :您可以提供的Function來處理接收到的響應。它採用status (數字), body (字符串) context (對象)參數和headers (鍵值對象)。使用workers時,您需要提供默認導出功能的文件路徑(查看工人部分以獲取更多詳細信息)可選
url :給定的目標。可以是HTTP或HTTP。允許多個URL,但建議連接的數量是URL的整數倍數。必需的。
socketPath :通往Unix域套接字或名為管道的窗口的路徑。仍然需要url發送正確的主機標頭和路徑。選修的。
workers :用於發射請求的工人線程數量。
connections :並發連接的數量。可選默認值: 10 。
duration :運行Autocannon的秒數。可以是時間段。可選默認值: 10 。
amount :一個Number說明在結束測試之前要提出的請求數。這覆蓋了持續時間並優先考慮,因此在完成需要完成的請求數量之前,測試才能結束。選修的。
sampleInt :在取樣之間逐漸消失的毫秒數。這控制了樣本間隔,因此會影響樣品總數,從而影響統計分析。默認值:1。
timeout :之前等待響應的秒數。可選默認值: 10 。
pipelining :每個連接的管道請求數量。將導致Client API在大於1時投擲。可選默認值: 1 。
bailout :在此實例釋放之前向服務器提出請求時,錯誤數的門檻。此實例將到目前為止取得所有現有結果,並將它們匯總到結果中。如果沒有任何傳遞在這裡,該實例將忽略錯誤,而永遠不會釋放。可選默認值: undefined 。
method :使用的HTTP方法。可選默認default: 'GET' 。
title :要添加到結果的String以進行標識。可選默認值: undefined 。
body :包含請求主體的String或Buffer 。通過包括[<id>] ,應插入隨機生成的ID(還必須將ID置換設置為true),將一個或多個隨機生成的ID插入到身體中。這對於浸泡測試端點可能很有用,其中一個或多個字段必須是唯一的。留下不確定的身體。可選默認值: undefined 。
form :包含多部分/表單數據選項的String或Object或包含它們的JSON文件的路徑
headers :包含請求標題的Object 。可選默認值: {} 。
initialContext :您想使用上下文的對象。查看初始化上下文的示例。選修的
setupClient :將傳遞每種連接的Client對象的Function 。這可用於使用下面顯示的API自定義每個單獨的連接標頭和車身。您在此功能中對客戶端的更改將優先於您在此處傳遞的默認body和headers 。樣本文件夾中有一個例子。可選默認值: function noop () {} 。使用workers時,您需要提供默認導出功能的文件路徑(請查看工人部分以獲取更多詳細信息)。
verifyBody :將通過每個完整請求傳遞響應主體的Function 。每個請求( verifyBody函數都不會返回真相值)都在mismatches中計數。此功能將優先於expectBody 。樣本文件夾中有一個例子。使用workers時,您需要提供默認導出功能的文件路徑(請查看工人部分以獲取更多詳細信息)。
maxConnectionRequests :一個Number說明最大請求是要進行每個連接。如果兩者都設置,則amount優先。選修的
maxOverallRequests :一個Number說明最大請求以使總體要求。不能比connections 。 maxConnectionRequests如果兩者都設置為優先級。選修的
connectionRate :一個Number說明請求率是從每個單獨連接中每秒提出的。默認情況下無率限制。選修的
overallRate :一個Number說明請求速率是從所有連接中每秒提出的。如果兩者都設置,則connectionRate優先。默認情況下無率限制。選修的
ignoreCoordinatedOmission :一種Boolean ,可以禁用延遲的校正,以補償協調的遺漏問題。當未指定請求率( connectionRate或overallRate )時,沒有意義。可選默認值: false 。
reconnectRate :一個使單個連接斷開連接並在發送該請求數時與服務器重新連接的Number 。選修的
requests : Object s Array ,代表基準測試時要提出的序列。可以與上面的body , headers和method參數結合使用。檢查樣品文件夾以獲取如何使用此文件的示例。選修的。包含的對象可以具有以下屬性:
har :解析HAR內容的Object 。 Autocannon將額外使用並使用entries.request重新: requests , method , form和body選項將被忽略。注意:您必須確保條目針對與url選項相同的域。選修的
idReplacement :一個Boolean ,可以用隨機生成的ID替換請求主體中的[<id>]標籤,從而可以隨請求發送唯一的字段。查看一個可以在樣本中找到的程序使用示例。可選默認值: false
forever :一個Boolean ,可讓您設置一個Autocannon的實例,該實例在done結果事件後無限期重新啟動。有效地重新啟動您的實例。要停止永遠運行,您必須在實例上引起SIGINT或調用.stop()函數。可選默認值: false
servername :識別SNI(服務器名稱指示)TLS擴展名的服務器名稱的String 。可選默認值:當URL不是IP地址時,將默認為“ URL的主機名”。
excludeErrorStats :一個Boolean ,可讓您禁用以延遲和每秒計算為字節的非2XX代碼響應。可選默認值: false 。
expectBody :代表預期響應主體的String 。每個響應主體都不等於expectBody的請求在mismatches中計算出來。如果啟用了,則不匹配對救助。選修的
tlsOptions :將其傳遞到tls.connect呼叫(選項的完整列表)中Object 。注意:僅當您的URL安全時,這才適用。
skipAggregateResult :一個Boolean ,可讓您禁用實例運行的匯總結果階段。請參閱Autocannon.ggregateresult
cb :完成基准後被調用的回調。獲取以下參數。選修的。
err :如果運行遇到錯誤。
results :運行的結果。
返回一個實例/事件發射器以跟踪進度等。如果省略了cb ,則返回值也可以用作承諾。
運行時,Autocannon將根據所需的連接創建盡可能多的Client對象。它們將平行運行,直到基準結束(請求的持續時間或總數)。每個客戶端將在requests數組中循環,它包含一個或幾個請求。
在瀏覽可用請求時,客戶端將維護context :您可以在onResponse和setupRequest函數中使用的對象,以存儲和讀取一些上下文數據。請檢查示例中的request-context.js文件。
請注意, context對象將重新啟動到第一個可用請求時,將重置為initialContext (或{} ),以確保類似的運行。
當將固定amount的請求與並發connections和overallRate限制結合在一起時,Autocannon將在所有連接上分配請求和預期速率。如果overallRate不可分割的整數不可分割,則Autocannon將配置一些連接客戶端具有較高的請求/秒/秒率較低的連接客戶端。如果現在的amount是整數可分開的,則所有連接客戶端都會獲得相同數量的請求。這意味著,請求率較高的客戶將比其他客戶更早完成,從而導致感知的請求率下降。
示例: connections = 10, overallRate = 17, amount = 5000
通過編程方式跟踪Autocannon的進度。
instance :Autocannon的實例。必需的。
opts :跟踪的配置選項。這可以具有以下屬性。選修的。
outputStream :輸出的流。默認值: process.stderr 。
renderProgressBar :實現進度標準的真實價值。默認值: true 。
renderResultsTable :實現結果表的渲染的真實價值。默認值: true 。
renderLatencyTable :實現高級延遲表的真實價值。默認值: false 。
progressBarString :一個定義進度顯示輸出格式的string 。對於Progress Bar模塊,必須是有效的輸入。默認值: 'running [:bar] :percent' 。
示例僅在完成時打印結果表:
'使用strict'Conconst autocannon = require('autocannon')const實例= autocannon({{
URL:'http:// localhost:3000'},console.log)//這用於在ctrl-cprocess.once上殺死實例('sigint',()=> {
instance.stop()})//僅渲染resultsautocannon.track(instance,{renderprogressbar:false})還查看此示例以查看使用中的示例。
返回包含結果表的文本字符串。
resultObject :Autocannon的結果對象。必需的。
opts :生成表的配置選項。這些可能包括以下屬性。選修的。
outputStream :輸出導向的流。它主要用於檢查終端是否支持顏色。默認值: process.stderr 。
renderResultsTable :實現結果表的創建的真實價值。默認值: true 。
renderLatencyTable :實現延遲表的創建的真實價值。默認值: false 。
例子:
“使用嚴格”; const {stdout} = require(“ node:process”); const autocannon = require(“ autocannon”); function print(結果){
stdout.write(autocannon.printresult(result));} autocannon({url:“ http:// localhost:3000”},(err,結果)=> print(rest)=> print(result));匯總一個或多個Autocannon實例運行的結果,其中Autocannon的實例已使用skipAggregateResult選項運行。
這是一個高級用例,您可能會在多個機器上使用Autocannon進行負載測試,因此需要將結果匯總到以後的時間。
results :Autocannon實例結果的數組,其中已將實例運行的情況下, skipAggregateResult選項設置為true。必需的。
opts :這是您將傳遞給主Autocannon API的選項的一個子集,因此您可以使用與運行實例相同的選項對象。有關選項的完整說明,請參見Autocannon。必需的。
url :必需
title :可選默認值: undefined
socketPath :可選
connections :可選默認值: 10 。
sampleInt :可選默認值: 1
pipelining :可選默認值: 1
workers :可選默認值: undefined
因為Autocannon實例是EventEmitter ,所以它發出了幾個事件。這些以下是:
start :一旦在您的Autocannon實例中設置了所有內容,並且已經開始。對於永遠運行實例的情況很有用。
tick :每秒發出此Autocannon正在運行基準。可用於顯示track功能使用的統計信息等。 tick事件傳播包含counter和bytes值的對象,可用於擴展報告。
done :當Autocannon完成基準測試時發出。將results作為參數傳遞給回調。
response :當Autocannons HTTP-CLIENT從服務器獲得HTTP響應時,發出。這將以下參數傳達給回調:
client : http-client本身。可用於修改客戶端將發送到服務器的標題和車身。下面的API。
statusCode :響應的HTTP狀態代碼。
resBytes :響應字節長度。
responseTime :啟動請求後獲得響應所花費的時間。
reqError :在請求錯誤的情況下發出,例如超時。
error :如果在Autocannon的設置階段存在錯誤,則發出。
done並傳遞給autocannon()回調的結果對象具有以下屬性:
title : title選項的價值傳遞給autocannon() 。
url :針對目標的URL。
socketPath :UNIX域套接字或名為“瞄准或undefined的窗戶。
requests :一個直方圖對象,其中包含有關每秒發送的請求數量的統計信息。
latency :包含有關響應延遲的統計信息的直方圖對象。
throughput :一個直方圖對象,其中包含有關每秒響應數據吞吐量的統計信息。
duration :測試所花費的時間,幾秒鐘。
errors :發生的連接錯誤數(包括超時)。
timeouts :發生的連接超時數量。
mismatches :與身體不匹配的請求數量。
start :代表測試何時開始的日期對象。
finish :表示測試結束時表示的日期對象。
connections :所使用的連接量( opts.connections的值)。
pipelining :每個連接使用的管道請求數( opts.pipelining的值)。
non2xx :接收到的非2XX響應狀態代碼的數量。
resets :由於setupRequest返回假值,請求管道被重置了多少次。
statusCodeStats :每個狀態代碼的請求計數器(例如{ "200": { "count": "500" } } )
requests , latency和throughput的直方圖對像是HDR-HISTRAGY-CERCEMILES-OBJ對象,並具有以下形狀:
min :此統計數據的最低值。
max :此統計數據的最高值。
average :平均值(平均)值。
stddev :標準偏差。
p* :此統計數據的xxth百分位數。百分位屬性為: p2_5 , p50 , p75 , p90 , p97_5 , p99 , p99_9 , p99_99 , p99_999 。
Client API該對像作為setupClient功能的第一個參數和來自Autocannon實例的response事件的第一個參數。您可以使用它來修改您在基準測試時發送的請求。這也是EventEmitter ,下面列出了事件及其參數。
client.setHeaders(headers) :用於修改該請求的標題此客戶端迭代器當前正在打開。 headers應該是一個Object ,或者如果要卸下標題,則undefined 。
client.setBody(body) :用於修改該請求的正文此客戶端迭代器當前正在打開。 body應該是String或Buffer ,如果要卸下身體,則應該undefined 。
client.setHeadersAndBody(headers, body) :用於修改該客戶端迭代器當前正在打開的標題和車身。 headers和body應採取與上面相同的形式。
client.setRequest(request) :用於修改此客戶端迭代器當前正在打開的整個請求。可以將headers , body , method或path作為屬性。默認為創建Autocannon實例傳遞到的值。 Note: call this when modifying multiple request values for faster encoding
client.setRequests(newRequests) :用於覆蓋啟動時傳遞到實例中的整個請求數組。 Note: call this when modifying multiple requests for faster encoding
Client事件Client可以發出的事件在此處列出:
headers :當從該客戶發送的請求收到其答复的標題時,發出。這接收到一個Object作為參數。
body :當從該客戶發送的請求收到答復正文時,發出。這將接收一個Buffer作為參數。
response :當客戶收到完成請求的完整響應時,發出。這通過以下參數:
statusCode :響應的HTTP狀態代碼。
resBytes :響應字節長度。
responseTime :啟動請求後獲得響應所花費的時間。
reset :由於setupRequest返回錯誤值而重置請求管道時發射。
使用Autocannon事件以及客戶端API和事件的示例:
'使用strict'Conconst autocannon = require('autocannon')const實例= autocannon({{
URL:'http:// localhost:3000',,
setUpclient:setUpclient},(err,結果)=> handleresults(result))//將結果傳遞給回調的結果與從完成eventsInstance.on('done',done',handleresults)instance.onsspect.on('tick ' ,()=> console.log('ticking'))instance.on('響應',handleresponse)function setupClient(client){
client.on('hody',console.log)// console.log響應主體}函數處理式handleresponse(客戶端,狀態代碼,resbytes,wonseptime){
console.log(`$ {wendestime} milliseconds`獲得代碼$ {statuscode}的響應)
console.log(`響應:$ {resbytes.tostring()}`)
//更新身體或標題
客戶端。
client.setbody(“新身體”)
客戶端。
// ...}Autocannon用node.js運行時的JavaScript編寫,並且是CPU綁定的。我們已經驗證了使用http模塊對Node.js應用程序進行基準測試時,它可以與wrk產生可比的結果。然而,它比將二進製文件(例如wrk編譯為二進制的其他工具的CPU要大得多。 Autocannon可以使CPU飽和,例如Autocannon工藝達到100%:在這種情況下,我們建議使用wrk2 。
例如,讓我們考慮一次運行,在服務器上具有1000個連接的運行,帶有4個帶有超線程的內核:
wrk使用2個線程(默認情況下)和一個輔助線程來收集CPU的總負載20% + 20% + 40%。
autocannon在80%CPU負載下使用單個線程。
兩者都在41k req/sec左右的node.js過程飽和,但是,由於單線讀取, autocannon可以更早飽和。
請注意, wrk不支持HTTP/1.1管道。結果, autocannon可以在服務器上與WRK相比,對於每個開放連接,可以創建更多的負載。
該項目是由近場贊助的。
由宇宙福克斯設計設計的徽標和身份:https://www.behance.net/cosmicfox。
WRK和WRK2提供了很大的靈感。
如果您使用的是Autocannon或您有任何疑問,請告訴我們:Gitter
格倫·基恩(Glen Keane)| github
Salman Mitha | github | NPM
版權所有Matteo Collina和其他貢獻者,在MIT下獲得許可。