The main thread starts N workers, waits for the warmup, lets them run for the duration, then joins them, merges their statistics and prints. All the work happens in the workers, and no worker waits on another. The front page draws one worker's loop.
- One thread, one ring
- Each worker owns an io_uring ring, set up with
SINGLE_ISSUER and DEFER_TASKRUN to keep kernel transitions to a minimum, plus its share of the connections (connections ÷ threads). There are no locks and no cross-thread messages on the hot path.
- Provided buffer ring
- Each worker registers 4,096 receive buffers of
--recv-buf bytes with the kernel up front. The kernel picks a buffer from that pool for incoming data, and the worker hands it back after parsing. Nothing is allocated per receive.
- Multishot receive
- One submission arms a continuous receive for a connection; from then on every arrival of data produces a completion with no further system call per receive. TLS connections use multishot
recvmsg so the worker can see TLS record types.
- Batched completions
- The loop takes up to 2,048 completions per iteration. Send and receive completions can land in the same batch, in either order, and the loop is written to handle both without stalling a pipeline.
- Pre-built requests
- Nothing is formatted per request. The pipeline buffer is built once; a template with a placeholder is copied into a per-connection scratch buffer and the value overwritten in place.
- Generation counters
- Every submission carries the connection's generation in its user data, so a completion that belongs to a connection since reconnected is recognised and dropped.
- Latency histogram
- Every response is recorded in a fixed two-tier histogram per worker: 1 µs buckets up to 10 ms, then 100 µs buckets up to 5 s. Percentiles are read from the merged histograms; anything longer is reported as overflow.
- Latency clock
- From the moment the send is prepared, not when the kernel completes it, to the moment the response is fully parsed.
--cqe-latency stops the clock at completion arrival instead; --rate starts it at the scheduled time.
- Warmup
- At least 100 ms, and until every connection has been set up or has failed once and is retrying, capped by
--warmup-max (10 s by default), and --settle then keeps the load running that much longer. Then each worker zeroes its own counters and the measured window begins. Ctrl-C during warmup exits with code 130 and prints no result.
- Teardown
- When the window closes, each worker ends its pending receives (
shutdown(SHUT_RD), which sends nothing) and closes its own connections, all workers at once, so nothing is left established when gcannon returns. On the wire the close is a FIN, or an RST with -r. The teardown is not part of the window: elapsed_sec ends when the last worker stopped counting.
- Idle connections
- Each opens, sends one request from its own path, reads the one response, then sits with a receive armed: the server’s close, or anything it sends, arrives as a completion and is counted. Nothing is ever sent on it again, and it is never reopened.
- The rate by thread
- With
--rate and --ramp-up, active connections come and go, so a connection’s own schedule would lose the total. Each thread keeps its share of it instead: a request every period, taken by the connection that has been free the longest. A slot that finds none free waits, and its latency counts from the slot.
- File table
- Opening connections inside the measured window would stall the workers each time the process’s file table has to grow, which several threads share. With
--ramp-up or --idle gcannon grows it once, before the threads start.
- Ramp steps
- With
--ramp-p99, the main thread steers the workers through a control word each one reads once per loop iteration, as the warmup’s reset already did: open the next step’s connections, zero the counters, or copy the stats out as a window closes. p99 is worked out from the merged copies once per step.
- Kernel TLS
- OpenSSL handles only the handshake. After it, the kernel encrypts and decrypts, so sends and receives stay ordinary io_uring operations on plaintext.