0802. Load-test topology: Linux containers in one network namespace on the dev machine; acceptance on separate hosts
Status: Accepted (2026-11-27). Work package H. Code: tools/loadtest/server.ts.
Context
Opening 100k sockets from a macOS host needs host changes: loopback aliases (macOS has only 127.0.0.1), and kern.maxfiles / kern.maxfilesperproc.
- The ephemeral range is 49152-65535, i.e. 16k ports per source address to one server port.
- macOS runs one gateway thread (no SO_REUSEPORT balancing), so its numbers are not production numbers either.
The dev machine is shared, and agents may not use sudo. Production is Linux (ADR 0020). Docker Desktop is available: its VM has 14 vCPUs and 16 GB, kernel 7.0, nr_open 1,048,576 and file-max 1.6M.
Decision
Dev-machine runs (--server docker, the default on macOS) use the production code in Linux containers. The image is node:26.4.0-trixie-slim: uWS.js needs glibc >= 2.38, so bookworm fails. The repo is mounted read-only. No host change is needed.
- Namespace container (
linora-lt-net, sleep infinity): owns the network namespace. It joins the compose network, so Postgres is at db:5432, and publishes the metrics port on 127.0.0.1.
- Container-scoped sysctls: ephemeral ports 10000-65535 (above 8788/9464, so a client never holds the server’s port while it restarts),
somaxconn and SYN backlog 65535, and short conntrack timeouts for closed connections.
- Docker’s embedded DNS puts NAT rules in the namespace, so every loopback connection is tracked against the VM-wide
nf_conntrack_max of 262,144. With the default TIME_WAIT of 120 s, a 100k kill plus reconnect storm would overflow it. Measured at 10k with the short timeouts: 10k entries idle, 18k right after a kill.
- Server container (
linora-lt-rt) joins that namespace and runs Linux defaults: 5 gateways with SO_REUSEPORT, 2 owners, --expose-gc for GC-settled memory readings. It is pinned to CPUs 0-7 (8 vCPU as in ADR 0020). It can be SIGKILLed or SIGTERMed and restarted without tearing the namespace down.
- Worker containers (
linora-lt-w<k>) join the same namespace, are pinned to the remaining CPUs, and connect over loopback. Each binds its own 127.1.k.x source addresses: the whole 127/8 is local on Linux, so there are no aliases and 55k ports per address.
- Measured: server process RSS, heap and CPU from
/metrics; container cgroup CPU (incl. kernel) and memory (incl. socket buffers); /proc/net/sockstat; conntrack.
What the dev machine can and cannot prove. Server and generator share one machine and one kernel.
- On loopback, part of the receiver’s TCP work is charged to the sender’s system time: an upper bound for the server’s kernel share.
- At ADR 0020 rates the generator needs ~0.5 core per 2,500 clients (measured at 10k), i.e. ~20 cores for 100k. The 6 cores left after the server’s 8 cannot drive the full-rate 100k run.
- So the dev machine proves the full connection count, memory, ramp, kill and storm behaviour, and validation cost at 100k, with activity scaled to fit (
--presence-hz 5 --batches 0.5 is 1/4 rate), plus full-rate behaviour up to ~15k clients. It also gives per-message CPU for projections.
Acceptance (PLAN WP-H) runs on separate Linux hosts.
- One 8 vCPU / 16 GB realtime box runs
apps/realtime as a service.
- One generator host with >= 32 vCPU, or several, runs
run.ts --server external with --src-ips for two or more source addresses, and --kill-cmd / --drain-cmd / --start-cmd (for example over ssh to systemd) for the kill and storm scenarios.
- Commands:
tools/loadtest/README.md.
Alternatives
- Host-native on macOS: needs sudo for aliases and maxfiles, and measures the wrong OS with 1 gateway.
- Server in Docker, generator on macOS through a published port: every connection goes through Docker Desktop’s userspace port proxy, which adds latency and CPU and hides the client addresses.
- Separate network namespaces over a bridge: closer to a NIC path, but it needs ephemeral-port tuning per container and gives the same kernel cost attribution problem on one machine.
- Raising
nf_conntrack_max in the VM: a privileged change to the shared Docker VM. Left to the user (README) and not needed at 100k with the short timeouts.
Consequences
- On the dev machine, the 100k run is one command with no host changes. The report states the mode, cpusets and the generator’s health.
- Absolute CPU from Docker Desktop on Apple silicon is indicative: virtualized, shared with other agents, loopback. The acceptance verdict for CPU and latency at 100k comes from the separate-host run.
Amendment (2026-11-28, after the 100k runs)
What the four 100k runs on this machine showed about the topology (results in tools/loadtest/results/2026-11-27-2*-100000c-*):
- The topology holds 100k connections. All 100,000 connected and synced in 51 s with no failures.
- Conntrack stayed at 100-103k entries through a kill and a drain storm, thanks to the short per-namespace timeouts.
- fd and port limits never bound.
- “Quarter rate” (
--presence-hz 5 --batches 0.5) is not a quarter of the server’s presence work. A room’s presence ticks at 20 Hz while any member moved, so a 30-room with 6 editors at 5 Hz still ticks nearly every 50 ms.
- The run offered 50k ops/s and 100k presence messages/s, and clients received ~730k frames/s.
- The generator is oversubscribed even at quarter rate. 16 workers on 6 CPUs reach worker event-loop lag p99 of 0.1-0.5 s, so client latencies are upper bounds. Clean client latency at 100k needs a separate generator host (README, option B).
- Overload runs cap the server container’s memory (
--server-memory 10g). Past saturation the server’s memory grows without bound (kernel socket buffers included), and the cap makes the OOM killer take the server container instead of Postgres or the shared VM.
- Reports now carry CPU per server thread (sampled from
/proc every 5 s) and latency per slice (--slice).
- Total cores hid the real limit: at 100k the 5 gateway threads sit at 97-99% from the first second of load while the total is ~6 of 8 cores.
- Window-wide percentiles mixed healthy minutes with the collapse.
Amendment (2026-11-28, R1 wave 3 runs)
- The dev machine holds a 20-minute 100k run, not reliably a 30-minute one.
- Two realistic attempts each held 100k live with the server flat at 3.3 cores and 1.6 GB, until about 30 min after start.
- Then every generator process inside the Docker VM froze at once, for up to 240 s: CPU pressure in the VM was 97%, and dockerd and containerd were the top CPU users. The server stayed healthy and idle, because its input stopped.
- The cause is on the VM or generator side (16 generator processes on 6 CPUs, plus Docker’s attach streams), not the server.
- The coordinator now survives a stalled worker: its data for that slice counts as missing and the report says so. Workers log a stall diagnostic to the run log.
- Full-length acceptance (30 min) at 100k needs the separate-host topology above (option B in tools/loadtest/README.md): an 8 vCPU realtime host and a generator host with >= 32 vCPU. The dev machine gives 20-minute windows plus kill and storm.