# wg/wrk architecture

> Architecture diagram of the GitHub repository wg/wrk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wg/wrk
- Repository: https://github.com/wg/wrk

## Overview

wrk is a multithreaded HTTP load generator. The user supplies a target URL, connection/thread/duration options, and optionally a Lua script; wrk runs concurrent requests, processes responses, and reports throughput, errors, and latency. The graph captures the documented Lua request/response/reporting capabilities and the sampled orchestration, event, socket, and statistics layers. Some runtime callback wiring is not visible in the excerpts, so those links are omitted or marked unverified.

Main entry points: [`src/wrk.c`](https://github.com/wg/wrk/blob/master/src/wrk.c) (CLI and runner), [`src/ae.c`](https://github.com/wg/wrk/blob/master/src/ae.c) (Event loop), [`src/script.c`](https://github.com/wg/wrk/blob/master/src/script.c) (Lua script runtime), [`src/net.c`](https://github.com/wg/wrk/blob/master/src/net.c) (Socket operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_benchmark["Benchmark runtime"]
  node_runner["CLI and runner<br/>[wrk.c]"]
  node_worker["Worker threads<br/>[wrk.c]"]
  node_eventloop["Event loop<br/>[ae.c]"]
  node_epoll["Epoll backend<br/>[ae_epoll.c]"]
  node_kqueue["Kqueue backend<br/>[ae_kqueue.c]"]
  node_evport["Event ports backend<br/>[ae_evport.c]"]
  node_select["Select backend<br/>[ae_select.c]"]
  node_memory["Memory allocation<br/>[zmalloc.c]"]
end

subgraph group_network["Network and HTTP"]
  node_sockets["Socket operations<br/>[net.c]"]
  node_tls["TLS transport<br/>[ssl.c]"]
  node_http["HTTP parser<br/>[http_parser.c]"]
end

subgraph group_scripting["Lua scripting"]
  node_lua["Lua script runtime<br/>[script.c]"]
end

subgraph group_metrics["Metrics and output"]
  node_stats["Statistics collection<br/>[stats.c]"]
  node_format["Units formatting<br/>[units.c]"]
end

node_user(("Benchmark user"))
node_target(("HTTP target"))

node_user -->|"configures"| node_runner
node_runner -->|"starts"| node_worker
node_runner -->|"initializes scripts"| node_lua
node_runner -->|"allocates statistics"| node_stats
node_worker -->|"connects and writes"| node_sockets
node_worker -.->|"registers events"| node_eventloop
node_eventloop -->|"selects backend"| node_epoll
node_eventloop -->|"selects backend"| node_kqueue
node_eventloop -->|"selects backend"| node_evport
node_eventloop -->|"selects backend"| node_select
node_sockets -.->|"sends requests"| node_target
node_sockets -.->|"uses secure transport"| node_tls
node_worker -.->|"parses responses"| node_http
node_worker -->|"generates requests"| node_lua
node_lua -->|"validates requests"| node_http
node_lua -->|"runs optional hooks"| node_user
node_runner -->|"aggregates results"| node_stats
node_runner -.->|"formats output"| node_format
node_runner -->|"prints report"| node_user
node_eventloop -->|"allocates loop state"| node_memory
node_lua -->|"allocates buffers"| node_memory

click node_runner "https://github.com/wg/wrk/blob/master/src/wrk.c"
click node_worker "https://github.com/wg/wrk/blob/master/src/wrk.c"
click node_eventloop "https://github.com/wg/wrk/blob/master/src/ae.c"
click node_epoll "https://github.com/wg/wrk/blob/master/src/ae_epoll.c"
click node_kqueue "https://github.com/wg/wrk/blob/master/src/ae_kqueue.c"
click node_evport "https://github.com/wg/wrk/blob/master/src/ae_evport.c"
click node_select "https://github.com/wg/wrk/blob/master/src/ae_select.c"
click node_sockets "https://github.com/wg/wrk/blob/master/src/net.c"
click node_tls "https://github.com/wg/wrk/blob/master/src/ssl.c"
click node_http "https://github.com/wg/wrk/blob/master/src/http_parser.c"
click node_lua "https://github.com/wg/wrk/blob/master/src/script.c"
click node_stats "https://github.com/wg/wrk/blob/master/src/stats.c"
click node_format "https://github.com/wg/wrk/blob/master/src/units.c"
click node_memory "https://github.com/wg/wrk/blob/master/src/zmalloc.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runner,node_worker,node_eventloop,node_epoll,node_kqueue,node_evport,node_select,node_memory,node_user toneBlue
class node_sockets,node_tls,node_http toneAmber
class node_lua toneMint
class node_stats,node_format toneRose
class node_target toneIndigo
```

## Components

### Benchmark runtime

- [CLI and runner](https://github.com/wg/wrk/blob/master/src/wrk.c): `src/wrk.c`
- [Worker threads](https://github.com/wg/wrk/blob/master/src/wrk.c): `src/wrk.c`
- [Event loop](https://github.com/wg/wrk/blob/master/src/ae.c): `src/ae.c`
- [Epoll backend](https://github.com/wg/wrk/blob/master/src/ae_epoll.c): `src/ae_epoll.c`
- [Kqueue backend](https://github.com/wg/wrk/blob/master/src/ae_kqueue.c): `src/ae_kqueue.c`
- [Event ports backend](https://github.com/wg/wrk/blob/master/src/ae_evport.c): `src/ae_evport.c`
- [Select backend](https://github.com/wg/wrk/blob/master/src/ae_select.c): `src/ae_select.c`
- [Memory allocation](https://github.com/wg/wrk/blob/master/src/zmalloc.c): `src/zmalloc.c`

### Network and HTTP

- [Socket operations](https://github.com/wg/wrk/blob/master/src/net.c): `src/net.c`
- [TLS transport](https://github.com/wg/wrk/blob/master/src/ssl.c): `src/ssl.c`
- [HTTP parser](https://github.com/wg/wrk/blob/master/src/http_parser.c): `src/http_parser.c`

### Lua scripting

- [Lua script runtime](https://github.com/wg/wrk/blob/master/src/script.c): `src/script.c`

### Metrics and output

- [Statistics collection](https://github.com/wg/wrk/blob/master/src/stats.c): `src/stats.c`
- [Units formatting](https://github.com/wg/wrk/blob/master/src/units.c): `src/units.c`

### Other components

- **Benchmark user**
- **HTTP target**

## Connections

- Benchmark user → CLI and runner: configures (evidence: `README.md`)
- CLI and runner → Worker threads: starts (evidence: `src/wrk.c`)
- CLI and runner → Lua script runtime: initializes scripts (evidence: `src/wrk.c`)
- CLI and runner → Statistics collection: allocates statistics (evidence: `src/wrk.c`)
- Worker threads → Socket operations: connects and writes (evidence: `src/wrk.c`)
- Worker threads → Event loop: registers events
- Event loop → Epoll backend: selects backend (evidence: `src/ae.c`)
- Event loop → Kqueue backend: selects backend (evidence: `src/ae.c`)
- Event loop → Event ports backend: selects backend (evidence: `src/ae.c`)
- Event loop → Select backend: selects backend (evidence: `src/ae.c`)
- Socket operations → HTTP target: sends requests
- Socket operations → TLS transport: uses secure transport
- Worker threads → HTTP parser: parses responses
- Worker threads → Lua script runtime: generates requests (evidence: `src/wrk.c`)
- Lua script runtime → HTTP parser: validates requests (evidence: `src/script.c`)
- Lua script runtime → Benchmark user: runs optional hooks (evidence: `README.md`)
- CLI and runner → Statistics collection: aggregates results (evidence: `src/wrk.c`)
- CLI and runner → Units formatting: formats output
- CLI and runner → Benchmark user: prints report (evidence: `src/wrk.c`)
- Event loop → Memory allocation: allocates loop state (evidence: `src/ae.c`)
- Lua script runtime → Memory allocation: allocates buffers (evidence: `src/script.c`)
