diff --git a/kernel/linux/DESIGN.md b/kernel/linux/DESIGN.md index d8a8b88c9..ee8ed6bb0 100644 --- a/kernel/linux/DESIGN.md +++ b/kernel/linux/DESIGN.md @@ -346,6 +346,32 @@ its one goroutine reading the UDP socket. Upstream kernel WireGuard scales with peers (each has its own tx worker and NAPI), from 10.0 to 16.9 Gbps at 8 CPUs. +At 50 Gbps (2026-11-07): router and backend c7i.48xlarge (192 vCPUs, +50 Gbps), 8 clients c7i.8xlarge (12.5 Gbps sustained), 16 flows each, all +192 router CPUs: + +| tunnel MTU | tswg | wireguard-go | kernel WG | plain | +|---|---|---|---|---| +| 1280 | 31504 Mbps (3.90 CPU-s/GB) | 7247 (3.87) | 12335 (94.7) | 49911 | +| 8920 | 49611 (2.18) | 17475 (1.86) | 49156 (15.0) | 49900 | + +* Jumbo MTUs are rare among Tailscale's customers (decided 2026-11-07: + the target is MTU 1280; jumbo results are only a data point). With + them (the VPC's MTU is 9001), tswg forwards at line rate, 2.8x + wireguard-go, using about 13 of the 192 CPUs. Kernel + WireGuard gets there too but with 7x the CPU per byte: its per-packet + round-robin worker kicks reach all 192 CPUs (at MTU 1280, 137 of them + busy for 12 Gbps), which tswg's on-demand kicks avoid. +* At Tailscale's MTU, 1280, EC2 limits each NIC receive queue to about + 715k packets per second (the router's ENA has 16), about 7.3 Gbps of + tunnel packets, and a peer's tunnel is one UDP flow, so one queue: a + single tunnel tops out there (tswg and wireguard-go alike, between any + c7i sizes), and with 8 peers, flows collide on queues (4 clients on 3 + queues: the two sharing got half each). More peers spread better; a + larger MTU needs 7x fewer packets. The router's CPUs weren't the limit. +* For 100 Gbps, the next step: c6in instances (up to 200 Gbps), which + the IAM policy doesn't allow yet. + Profile of the tswg router at 4 CPUs (CPU-bound), before the optimizations: ChaCha20-Poly1305 about 23% (of which 5.5% was a scalar ChaCha20 block per message for its Poly1305 key), the ENA driver about diff --git a/kernel/linux/scripts/ec2.sh b/kernel/linux/scripts/ec2.sh index 1d4f30d7d..eb3977a54 100755 --- a/kernel/linux/scripts/ec2.sh +++ b/kernel/linux/scripts/ec2.sh @@ -27,7 +27,9 @@ # # usage: # ec2.sh up [COUNT [TYPE]] launch COUNT (default 2) instances of TYPE (default c7i.xlarge) -# ec2.sh start start stopped instances, and rewrite the hosts file +# ec2.sh start [N...] start stopped instances (all, or those numbered N), +# and rewrite the hosts file +# ec2.sh resize TYPE N... change stopped instances N... to TYPE # ec2.sh stop stop the instances (as ec2-idle-stop.sh does) # ec2.sh hosts rewrite the hosts file from the running instances # ec2.sh ssh N [CMD...] ssh to instance N (0-based) @@ -69,6 +71,16 @@ instance_ids() { --query 'Reservations[].Instances[].InstanceId' --output text } +# ids_of N... prints the IDs of our (not terminated) instances numbered N. +ids_of() { + for n in "$@"; do + ec2 describe-instances --filters "Name=tag:owner,Values=claude-tswg" \ + "Name=tag:Name,Values=$name-$n" \ + "Name=instance-state-name,Values=pending,running,stopping,stopped" \ + --query 'Reservations[].Instances[].InstanceId' --output text + done | tr '\n' ' ' +} + ensure_key() { if [ ! -f "$key" ]; then ssh-keygen -q -t ed25519 -N '' -C "$name" -f "$key" @@ -178,16 +190,12 @@ up) ami=$(aws ssm get-parameter \ --name /aws/service/canonical/ubuntu/server/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id \ --query Parameter.Value --output text) - stopped=$(ec2 describe-instances --filters "Name=tag:owner,Values=claude-tswg" \ - "Name=instance-state-name,Values=stopping,stopped" \ - --query 'length(Reservations[].Instances[])' --output text) - if [ "$stopped" != 0 ]; then - echo "$stopped instances are stopped; use \"$0 start\" (or \"$0 down\" first)" >&2 - exit 1 - fi + # Number new instances after all existing ones, stopped ones included. existing=$(ec2 describe-instances --filters "Name=tag:owner,Values=claude-tswg" \ - "Name=instance-state-name,Values=pending,running" \ - --query 'length(Reservations[].Instances[])' --output text) + "Name=instance-state-name,Values=pending,running,stopping,stopped" \ + --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]' --output text | + tr '\t' '\n' | sed -n "s/^$name-//p" | sort -n | tail -1) + existing=$((${existing:--1} + 1)) ids="" i=$existing while [ "$i" -lt $((existing + count)) ]; do @@ -214,9 +222,13 @@ up) cat "$hosts" ;; start) - ids=$(ec2 describe-instances --filters "Name=tag:owner,Values=claude-tswg" \ - "Name=instance-state-name,Values=stopping,stopped" \ - --query 'Reservations[].Instances[].InstanceId' --output text) + if [ $# -gt 0 ]; then + ids=$(ids_of "$@") + else + ids=$(ec2 describe-instances --filters "Name=tag:owner,Values=claude-tswg" \ + "Name=instance-state-name,Values=stopping,stopped" \ + --query 'Reservations[].Instances[].InstanceId' --output text) + fi if [ -n "$ids" ]; then # shellcheck disable=SC2086 ec2 wait instance-stopped --instance-ids $ids @@ -230,6 +242,17 @@ start) wait_ready cat "$hosts" ;; +resize) + type=$1 + shift + ids=$(ids_of "$@") + # shellcheck disable=SC2086 + ec2 wait instance-stopped --instance-ids $ids + for id in $ids; do + ec2 modify-instance-attribute --instance-id "$id" --instance-type "Value=$type" + echo "$id is now $type" >&2 + done + ;; stop) ids=$(instance_ids) if [ -n "$ids" ]; then