Skip to main content

Stress Testing Headscale at 200+ Concurrent Clients

· 5 min read
Larktun Contributor

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 N nodes share visibility in the same tailnet, a single online/offline transition can trigger O(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:

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:

RoleRecommended SpecPurpose
Load generator host16 vCPU / 32 GB RAM / 100 GB NVMeRuns 200 lightweight client containers, churn loop, and traffic workers
Target Headscale host4 vCPU / 8 GB RAM / 100 GB SSDIsolated control-plane CPU, RAM, DB I/O, and goroutine measurement
Optional DERP relay2–4 vCPU / 2–4 GB RAMMeasures 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/tun device access, and pre-pulls images so bootstrap timings reflect control-plane registration rather than registry downloads.
  • 01_bootstrap_up.sh: Spins up REPLICAS client containers using a reusable pre-authentication key (TS_AUTHKEY) and waits for them to register against HEADSCALE_URL.
  • 02_list_nodes.sh: Writes nodes.tsv mapping each container name to its assigned tailnet IPv4 address for downstream traffic scripts.
  • 03_churn.sh: Every CHURN_INTERVAL seconds, randomly cycles CHURN_BATCH_PERCENT of containers through up/down/restart to emulate real-world roaming networks and flaky endpoints.
  • 04_traffic_round.sh: Selects TRAFFIC_PAIR_COUNT random source-destination pairs from nodes.tsv and 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:

  1. Client convergence: Confirm all 200 replicas reach online status without prolonged registration backoff.
  2. Control-plane CPU profile: Watch whether CPU stays flat during steady state and how quickly spikes decay during 03_churn.sh waves. Sustained high CPU during 10% batch churn indicates full-netmap rebuild pressure.
  3. Memory footprint: Track both Headscale resident memory (ensuring no unbounded map-response goroutine leaks) and per-client container memory on the generator host.

200 simulated clients online in Headscale

Headscale control-plane CPU utilization during churn and traffic rounds

Client container memory usage across 200 replicas

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.

Continue Reading​