$ show mcollina/autocannon
autocannon is a high-performance HTTP/1.1 benchmarking tool written in Node.js, inspired by wrk and wrk2. It operates as both a CLI tool and a programmable library. The architecture is centered around a run loop that manages multiple concurrent HTTP clients, each capable of pipelining requests. Key components include a request builder that constructs raw HTTP request buffers, a pipelined request queue for handling out-of-order responses, and a histogram-based statistics engine using hdr-histogram-js with WebAssembly for efficient percentile calculations. The tool supports HTTPS, Unix sockets, multipart forms, HAR file replay, worker threads for parallel execution, rate limiting with coordinated omission correction, and extensive customization via setup functions and event hooks. The codebase is well-structured with clear separation of concerns, comprehensive test coverage, and active maintenance.
The LLM identified 2 files worth highlighting for reuse:
A self-contained FIFO queue class designed to manage pipelined HTTP requests and link metadata (headers, body, byte count, start time) to each request as responses arrive. It provides precise duration calculation using process.hrtime. This component is isolated, well-documented, and can be extracted and reused in any project requiring ordered request-response tracking with timing, such as custom HTTP clients or protocol implementations.
A factory function that returns a request builder curried with default options. It constructs raw HTTP/1.1 request buffers from a request object, handling method, path, headers, body (string, Buffer, or number), authentication, Content-Length calculation, and idReplacement for dynamic IDs. It also supports a setupRequest hook for per-request mutation. This module is decoupled from the rest of autocannon and can be reused in any Node.js project that needs to programmatically build HTTP request buffers without using the http module.