autocannon
Ultra-fast HTTP/1.1 benchmarking tool built for Node.js. Powered by uWebSockets, it measures latency percentiles (p50, p90, p99), requests per second, and throughput — from the CLI or embedded directly in your Node.js scripts and CI pipelines.
What is autocannon?
autocannon is an open-source HTTP benchmarking tool written entirely in Node.js by Matteo Collina, a Node.js core contributor. It uses uWebSockets to generate high-throughput load against HTTP/1.1 and HTTPS endpoints, making it significantly faster than tools implemented in pure JavaScript.
Unlike heavier load-testing platforms, autocannon focuses on raw HTTP performance measurement: how fast does your server respond, what are the tail latencies, how many requests per second can it sustain? It works as a command-line tool for quick benchmarks and as a Node.js module for embedding performance gates in automated test suites and CI pipelines.
Key Features
- Ultra-fast engine — built on uWebSockets for maximum request throughput from a single Node.js process
- Configurable load — set concurrent connections, pipelining factor, duration, or total request count
- Latency percentiles — reports p50, p75, p90, p97.5, p99, p99.9, p99.99 via HDR histograms
- HTTP & HTTPS — benchmarks both plain HTTP and TLS-secured HTTPS endpoints
- Programmatic API — use
autocannon()in Node.js scripts, tests, and CI jobs - POST / custom methods — set method, headers, and body for any HTTP verb
- HTTP pipelining — send multiple requests per connection without waiting for responses
- JSON output — machine-readable results for dashboards and performance regression tracking
Installation
# Install globally npm install -g autocannon # Or add to a project as a dev dependency npm install --save-dev autocannon # Verify installation autocannon --version
CLI Usage
The CLI covers most benchmarking scenarios: set -c for connections,
-d for duration in seconds, -m for HTTP method,
-H for headers, and -b for a request body.
# Benchmark a GET endpoint for 10 seconds with 10 connections
autocannon -c 10 -d 10 http://localhost:3000/api/users
# POST with JSON body and custom header
autocannon -c 20 -d 30 \
-m POST \
-H "Content-Type: application/json" \
-b '{"name":"test","email":"[email protected]"}' \
http://localhost:3000/api/users
# 100 connections, 1000 total requests (instead of duration)
autocannon -c 100 -a 1000 http://localhost:3000/
# Enable HTTP pipelining (4 requests per connection)
autocannon -c 10 -p 4 -d 10 http://localhost:3000/
# Output results as JSON (useful for CI pipelines)
autocannon -c 10 -d 5 --json http://localhost:3000/ > results.json
# Benchmark with a custom Authorization header
autocannon -c 50 -d 20 \
-H "Authorization: Bearer " \
https://api.example.com/protected Programmatic API
Import autocannon as a Node.js module to run benchmarks from scripts, Mocha/Jest test files, or custom tooling. The returned Promise resolves with a structured results object containing all latency, throughput, and error statistics.
// benchmark.js — programmatic API
const autocannon = require('autocannon');
async function run() {
const result = await autocannon({
url: 'http://localhost:3000/api/items',
connections: 20, // concurrent connections
pipelining: 1, // HTTP pipelining factor
duration: 10, // seconds
method: 'GET',
headers: {
'accept': 'application/json',
},
});
// result contains full latency/throughput statistics
console.log('Requests/sec:', result.requests.average);
console.log('Throughput: ', result.throughput.average, 'bytes/sec');
console.log('Latency p50: ', result.latency.p50, 'ms');
console.log('Latency p99: ', result.latency.p99, 'ms');
console.log('Errors: ', result.errors);
}
run(); CI Performance Gates
Combine the programmatic API with process.exit(1) to fail a CI build when latency or throughput regresses past defined thresholds. Run this script after deploying to a staging environment to catch performance regressions before they reach production.
// ci-benchmark.js — fail the build if p99 latency exceeds threshold
const autocannon = require('autocannon');
async function benchmark() {
const result = await autocannon({
url: process.env.TARGET_URL || 'http://localhost:3000/',
connections: 10,
duration: 10,
});
const p99 = result.latency.p99;
const rps = result.requests.average;
console.log(`p99 latency: ${p99}ms | RPS: ${rps}`);
if (p99 > 200) {
console.error(`FAIL: p99 ${p99}ms exceeds 200ms threshold`);
process.exit(1);
}
console.log('PASS: performance within acceptable thresholds');
}
benchmark(); autocannon vs wrk vs ab
| Feature | autocannon | wrk | ab (ApacheBench) |
|---|---|---|---|
| Language | Node.js | C | C |
| Programmatic API | Yes (Node.js) | Lua scripts only | No |
| Latency percentiles | Yes (HDR histogram) | Yes | Limited |
| HTTP pipelining | Yes | No | No |
| JSON output | Yes | No | Partial |
| Install (Node environment) | npm install -g autocannon | Compile from source | System package manager |
Pros and Cons
Pros
- ✓ npm install — zero native dependencies, works anywhere Node runs
- ✓ Programmatic API fits naturally into Node.js CI scripts
- ✓ Accurate HDR histogram latency percentiles up to p99.99
- ✓ HTTP pipelining support for testing pipeline-capable servers
- ✓ JSON output for storing and comparing benchmark history
Cons
- ✗ HTTP/1.1 only — no HTTP/2 or HTTP/3 support
- ✗ Node.js runtime adds slight overhead vs pure C tools like wrk
- ✗ No built-in scenario scripting (multiple URLs, ramp-up phases)
- ✗ Single-machine load generation; no distributed test coordination
- ✗ Not designed for long-soak or multi-step user journey tests
Frequently Asked Questions
What is autocannon?▼
autocannon is a fast HTTP/1.1 benchmarking tool written in Node.js by Matteo Collina, one of the Node.js core contributors. It uses uWebSockets under the hood to generate high-throughput load against HTTP and HTTPS endpoints. It reports latency percentiles (p50, p90, p99, p99.9), requests per second, throughput in bytes per second, and error counts. It works both as a CLI tool and as a Node.js programmatic API, making it easy to embed in scripts and CI pipelines.
How does autocannon compare to wrk and ab (ApacheBench)?▼
wrk is a C-based tool that produces very low overhead and high request rates, making it ideal for raw maximum throughput tests. ab (ApacheBench) is the oldest of the three and the simplest but lacks modern features like percentile histograms. autocannon sits between them: it runs on Node.js (so it is easy to install anywhere Node is available), supports a programmatic API for embedding in test suites, and outputs detailed latency percentiles. For pure raw numbers wrk may edge out autocannon, but autocannon is far easier to integrate into JavaScript/Node.js projects and CI workflows.
How do I benchmark a POST endpoint with a JSON body?▼
Use the -m POST flag to set the HTTP method, -H to add a Content-Type header, and -b to supply the request body. For example: autocannon -c 10 -d 10 -m POST -H "Content-Type: application/json" -b '{"key":"value"}' http://localhost:3000/api. In the programmatic API, pass method, headers, and body fields to the options object passed to autocannon().
What metrics does autocannon report?▼
autocannon reports: latency statistics (mean, standard deviation, min, max, and percentiles p2.5, p50, p75, p90, p97.5, p99, p99.9, p99.99), requests per second (mean, standard deviation, min, max, total), throughput in bytes per second (mean, standard deviation, min, max, total), total requests sent, total bytes received, connection errors, timeout errors, and non-2xx response counts. All percentile data comes from HDR histograms for accuracy at high sample counts.
Can autocannon be used programmatically in Node.js tests?▼
Yes — that is one of autocannon's key strengths over CLI-only tools. Install it as a dev dependency and require or import it in your test or benchmark script. The autocannon() function accepts a configuration object and returns a Promise that resolves with the full results object. You can then assert on result.latency.p99 or result.requests.average to fail a CI build if performance regresses. This makes it straightforward to add automated performance gates alongside your unit and integration tests.
What is HTTP pipelining and how does autocannon support it?▼
HTTP pipelining allows multiple requests to be sent on the same TCP connection without waiting for each response before sending the next. This can increase throughput significantly for servers that support it. autocannon enables pipelining via the -p flag on the CLI (e.g., -p 4 sends 4 requests per connection without waiting) or the pipelining option in the programmatic API. Note that HTTP/1.1 pipelining is not universally supported or beneficial — most modern servers and proxies disable it in favor of HTTP/2 multiplexing, so test with and without to compare results.
Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
HTTP Status Code Reference
Complete HTTP status code reference. Search all 1xx, 2xx, 3xx, 4xx, and 5xx codes with plain-English descriptions, real-world use cases, and when to use each in REST APIs.
Open free tool →
CSS Clip-Path Generator
Generate CSS clip-path values visually. Choose from 16 polygon presets (triangle, star, arrow, hexagon), circle, ellipse, and inset shapes. Live preview, one-click copy. Free, no signup.
Open free tool →
HTTP Status Code Reference
Complete HTTP status code reference. Look up all 1xx, 2xx, 3xx, 4xx, and 5xx codes with plain-English descriptions, real-world use cases, and when to use each. Searchable and filterable.
Open free tool →
More Free Tools
Related Articles
curl 深度使用手冊:API 測試從入門到進階
curl 是每位開發者必備的 CLI 工具。本文涵蓋 GET/POST/PUT/DELETE 請求、認證、header 設定、檔案上傳、除錯技巧,以及 REST API 測試的完整實戰範例。
Node.js 22 Performance Guide: Worker Threads, Cluster Mode, and V8 Optimizations
Maximize Node.js 22 performance with Worker Threads for CPU-bound tasks, Cluster mode for multi-core utilization, V8 optimization tips, profiling tools, and memory management best practices.
Redis Caching Patterns for Node.js Applications
Master Redis caching in Node.js with practical patterns: cache-aside, write-through, cache invalidation, TTL strategies, pub/sub, and production-ready implementation with ioredis.
Redis Caching Strategies for Node.js Applications
Master Redis caching in Node.js. Learn Cache-Aside, Write-Through, and Write-Back patterns with practical code examples, TTL strategies, and cache invalidation techniques.
Bun 2.0 New Features Deep Dive: Bundler, Hot Reload, Package Manager & Runtime Upgrades
Bun 2.0 complete guide: new bundler improvements, hot reload enhancements, package manager upgrades, Node.js compatibility gains, and performance benchmarks for 2026.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →