Skip to main content

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.

✓ HTTP & HTTPS ✓ Latency percentiles ✓ Programmatic API ✓ HTTP pipelining ✓ JSON output ✓ CI-friendly

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

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)
LanguageNode.jsCC
Programmatic APIYes (Node.js)Lua scripts onlyNo
Latency percentilesYes (HDR histogram)YesLimited
HTTP pipeliningYesNoNo
JSON outputYesNoPartial
Install (Node environment)npm install -g autocannonCompile from sourceSystem 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.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

HTTP Status Code Reference CSS Clip-Path Generator HTTP Status Code Reference HTTP Status Code Lookup HTTP Status Code Lookup Web Performance Checklist HTTP Methods Reference HTTP Headers Analyzer API Request Builder HTTP API Tester HTTP Headers Inspector HTTP Status Code Reference HAR Diff Analyzer WebSocket Test Client HTTP Cache-Control Builder HTTP Header Analyzer HTTP/2 Server Push Headers Builder NATS Connection String Builder Lighthouse Score Simulator HTTP Security Headers Checker Web Vitals Budget Planner HTTP Cache Header Builder GraphQL Client Configurator Turso Edge DB Explorer Core Web Vitals Guide API Response Formatter & Analyzer API Response Mock Generator curl Command Builder Git Command Builder HTTP Security Headers Generator HTTP Code Snippet Generator Developer Utilities WebSocket Tester JSON Path Finder HTTP Mock Response Builder Web Vitals Scorer Webhook Tester SQL Index Advisor Haproxy Config Validator Caddy Caddyfile Generator Redis Command Tester MySQL Query Explainer PostgreSQL EXPLAIN Analyzer Docker Run Command Builder CI/CD Pipeline Generator package.json Generator k6 Load Test Script Generator OAuth2 Flow Visualizer mTLS Certificate Chain Builder Web Vitals Analyzer SSL Certificate Checker Database Index Analyzer REST API Request Builder Mock Service Worker (MSW) API Mocking Guide AES Encryptor / Decryptor Core Web Vitals Calculator Database Index Advisor API Response Mocker ArgoCD Application Generator LLM Benchmark Calculator OpenTelemetry Trace Builder k6 Script Generator Core Web Vitals Budget Calculator Bundle Size Budget Calculator Image Optimization Calculator TTFB Analyzer Database Query Cost Analyzer

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →