Stress Testing Headscale at 200+ Concurrent Clients
Running a small self-hosted headscale instance for ten personal devices is effortless. Operating Headscale as a production multi-user control plane is a completely different workload: every node join, disconnect, route change, or key rotation triggers map-response updates across peers. Before scaling Headscale into a multi-tenant SaaS control plane, you need repeatable load tests that measure both steady-state overhead and reconnect storms.
This guide documents a reproducible stress-testing workflow for 200+ concurrent clients using containerized Tailscale nodes, automated churn injection, and randomized TCP/UDP traffic sampling.
Why Control-Plane Load Testing Matters
In a WireGuard mesh coordinated by Headscale, the data plane flows peer-to-peer (or via DERP relays), while the control plane coordinates authentication, node state, ACL compilation, and netmap distribution. At higher node counts, bottlenecks rarely come from idle nodes—they come from state fan-out:
- Netmap broadcast amplification: When
Nnodes share visibility in the same tailnet, a single online/offline transition can triggerO(N)map-response updates. - Reconnect churn storms: Mobile devices switching between Wi-Fi and cellular networks or containers restarting in waves can spike CPU, PostgreSQL/SQLite lock contention, and memory allocations simultaneously.
- DERP fallback contention: Under strict NAT conditions, validating whether relay bandwidth and file descriptor limits hold steady during peer-to-peer and relayed traffic rounds prevents surprises in production.
Test Harness Repository
All automation scripts used in this benchmark are open source:
- Repository: OwnDing/headscale-test-scripts
Recommended Machine Sizing (200 Clients)
Running 200 client containers on the same host as the control plane skews CPU and memory telemetry. Separate the load generator from the target Headscale node:
| Role | Recommended Spec | Purpose |
|---|---|---|
| Load generator host | 16 vCPU / 32 GB RAM / 100 GB NVMe | Runs 200 lightweight client containers, churn loop, and traffic workers |
| Target Headscale host | 4 vCPU / 8 GB RAM / 100 GB SSD | Isolated control-plane CPU, RAM, DB I/O, and goroutine measurement |
| Optional DERP relay | 2–4 vCPU / 2–4 GB RAM | Measures relay throughput and socket concurrency under NAT fallback |
Before launching 200+ containers on the load generator, verify that host kernel limits will not bottleneck container startup (fs.inotify.max_user_instances, fs.file-max, and Docker bridge subnet pools).
Step-by-Step Stress-Test Runbook
Clone the repository onto the load-generator host and execute the scripts in order:
# 1) Copy and customize environment configuration
cp .env.example .env
# 2) Verify Docker, Compose, /dev/net/tun, and pre-pull container images
bash scripts/00_check_env.sh
# 3) Bootstrap simulated clients (defaults to 200 replicas)
bash scripts/01_bootstrap_up.sh
# 4) Export active containers and their assigned Tailnet IPv4 addresses
bash scripts/02_list_nodes.sh
# 5) Start continuous reconnect churn (Terminal A)
bash scripts/03_churn.sh
# 6) Run periodic random pair TCP/UDP traffic rounds (Terminal B)
watch -n 20 'bash scripts/04_traffic_round.sh'
# 7) Tear down all test containers and clean up state
bash scripts/99_cleanup.sh
Key Environment Variables
Tune concurrency, churn aggressiveness, and traffic intensity in .env:
HEADSCALE_URL=https://headscale.example.com
TS_AUTHKEY=tskey-auth-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
REPLICAS=200
CHURN_INTERVAL=30
CHURN_BATCH_PERCENT=10
TRAFFIC_PAIR_COUNT=30
TRAFFIC_TCP_DURATION=10
TRAFFIC_TCP_PARALLEL=4
TRAFFIC_UDP_DURATION=10
TRAFFIC_UDP_BW=50M
What Each Script Does
00_check_env.sh: Validates Docker daemon availability, Compose CLI,/dev/net/tundevice access, and pre-pulls images so bootstrap timings reflect control-plane registration rather than registry downloads.01_bootstrap_up.sh: Spins upREPLICASclient containers using a reusable pre-authentication key (TS_AUTHKEY) and waits for them to register againstHEADSCALE_URL.02_list_nodes.sh: Writesnodes.tsvmapping each container name to its assigned tailnet IPv4 address for downstream traffic scripts.03_churn.sh: EveryCHURN_INTERVALseconds, randomly cyclesCHURN_BATCH_PERCENTof containers throughup/down/restartto emulate real-world roaming networks and flaky endpoints.04_traffic_round.sh: SelectsTRAFFIC_PAIR_COUNTrandom source-destination pairs fromnodes.tsvand runs parallel TCP and UDP benchmarks to confirm that data-plane forwarding remains healthy while the control plane is under churn.99_cleanup.sh: Stops and removes all test containers, networks, and temporary sidecar state.
Observing Results and Identifying Bottlenecks
During the 200-client run, monitor three key telemetry dimensions simultaneously:
- Client convergence: Confirm all 200 replicas reach
onlinestatus without prolonged registration backoff. - Control-plane CPU profile: Watch whether CPU stays flat during steady state and how quickly spikes decay during
03_churn.shwaves. Sustained high CPU during 10% batch churn indicates full-netmap rebuild pressure. - Memory footprint: Track both Headscale resident memory (ensuring no unbounded map-response goroutine leaks) and per-client container memory on the generator host.



Key Architectural Takeaways
Running this benchmark repeatedly highlighted the exact bottlenecks that must be solved before scaling Headscale to thousands of tenants:
- Isolate blast radius: Putting every user into a single shared tailnet causes linear-to-quadratic map broadcast overhead during churn. Strict tenant boundaries keep each update scoped to a small peer set.
- Avoid full netmap rebuilds: Debouncing dirty events and recomputing only affected tenant/tag scopes dramatically cuts control-plane CPU under frequent mobile reconnects.
- Shard horizontally: Moving from a monolithic single instance to
cluster_id-partitioned nodes allows capacity to scale linearly as device counts grow.