Skip to content
Latchkey

autocannon -c -d: Node HTTP Benchmarking

autocannon -c 100 -d 30 -p 10 http://localhost:8080/ runs 100 connections for 30 seconds with 10 pipelined requests each, printing latency and req/sec tables.

autocannon is the Node ecosystem benchmarker, installable with npm and scriptable in JS. -c sets connections, -d the duration in seconds, and -p the pipelining factor, and it flags non-2xx responses that a naive check would miss.

What it does

autocannon opens -c connections for -d seconds, optionally pipelining -p requests per connection, and prints latency and request/sec percentile tables plus counts of 2xx and non-2xx responses. Run it via npx autocannon or programmatically for custom gating.

Common usage

Terminal
# 100 connections, 30s, pipelining 10
npx autocannon -c 100 -d 30 -p 10 http://localhost:8080/

# POST with a body and a header
npx autocannon -c 50 -d 20 \
  -m POST -H 'Content-Type=application/json' \
  -b '{"k":"v"}' http://localhost:8080/api

Options

FlagWhat it does
-c, --connections NConcurrent connections (default 10)
-d, --duration NDuration in seconds (default 10)
-p, --pipelining NRequests to pipeline per connection
-m, --method <M>HTTP method
-b, --body <data>Request body
-H, --headers <k=v>Add a header
-a, --amount NSend exactly N requests then stop

In CI

Run programmatically (autocannon(opts, cb)) and inspect result.non2xx and result.latency.p99, throwing to fail the job, or use a wrapper like autocannon-compare. From the CLI, check that the 2xx count matches the request total and that Latency p99 is within budget. Warm up first: the first second of a Node target is often JIT-cold.

Common errors in CI

autocannon: command not found means it is not installed; use npx autocannon or npm i -g autocannon. connect ECONNREFUSED 127.0.0.1:8080 means the server was not ready. High non2xx with low 2xx means the endpoint returned errors under load even though autocannon exits 0, so gate on the counts. Very high -p can overflow server buffers and produce read timeouts; lower pipelining.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →