用节点编写的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下获得许可。