6 min readResearchEdge RoutingLatency

Measuring Tail Latency Across Multi-Tenant Edge Proxies

What happened when we stopped looking at median response times and profiled p99.9 latency under mixed TLS handshakes, route table reloads, and upstream keep-alive contention.

For the first six months of running Weond's edge proxy, our p50 numbers looked great. Static assets came back in 6–9 ms, API forwards added less than 2 ms of proxy overhead, and CPU stayed under 25% even during burst traffic.

Then a user sent us a HAR file from a checkout flow in Frankfurt. Most requests took 14 ms. Three of them, scattered across a two-minute session, took between 310 ms and 480 ms. Nothing in our aggregate dashboards had tripped an alert because p50 and even p95 were completely flat.

This report documents the four-week profiling pass we ran to find where those 300 ms spikes came from, what we measured before and after each change, and which fixes actually moved p99.9 instead of just looking good in synthetic microbenchmarks.

Benchmark setup and methodology

Synthetic HTTP benchmarks are notoriously bad at reproducing multi-tenant tail latency. Running wrk against a single hostname with 100 persistent connections hides almost every real bottleneck: SNI certificate lookups, cold route entries, mixed HTTP/1.1 and HTTP/2 clients, and background control-plane writes.

To mirror production traffic more faithfully, we built a replay harness against a staging edge node (8 vCPU, 16 GB RAM, Linux 6.8, NVMe) with the following mix:

  • 1,400 active hostnames registered in the routing table, with a Zipf distribution (top 40 hosts receiving 68% of traffic, the rest long-tail).
  • 12,000 requests/sec sustained for 20 minutes per run, with 15% of connections forcing a fresh TLS 1.3 handshake rather than reusing a session ticket.
  • Control-plane churn injected continuously: 8 route updates per second (simulating deployments, custom domain binds, and preview branch teardowns).
  • Mixed upstreams: 60% local static artifact reads, 40% proxied HTTP upstreams with artificial 8 ms ± 2 ms response jitter.

Every latency number below was captured on the client load generator (including TLS and socket write time, not just proxy internal timers) to avoid coordinated omission.

Baseline measurements

Our initial proxy implementation was already written in Rust on top of Tokio and Hyper. We expected the culprit to be disk I/O or TLS handshake CPU. We were mostly wrong.

Metric Baseline (RwLock + shared pool) After RCU route snapshots After sharded pools + TLS cache
p50 9.4 ms 9.1 ms 8.8 ms
p95 21.8 ms 19.4 ms 17.6 ms
p99 74.2 ms 38.9 ms 26.1 ms
p99.9 412.6 ms 148.3 ms 41.8 ms
Max observed 689.0 ms 291.4 ms 79.2 ms

The p50 barely moved across the entire investigation (9.4 ms down to 8.8 ms). Meanwhile, p99.9 dropped by roughly 10x.

Finding 1: Write starvation on the routing table

Our routing table lived behind an Arc<tokio::sync::RwLock<RouteMap>>. On paper, RwLock sounds ideal for a read-heavy workload: thousands of readers per second, a handful of writers.

In practice, Tokio's RwLock is write-preferring to prevent writer starvation. Whenever a deployment pushed a route update, the pending writer immediately queued all incoming readers behind it until every in-flight reader released its guard. If a single reader held the lock across a slow path (for example, resolving a fallback rule or logging a structured trace), hundreds of new requests piled up behind the writer for 80–250 ms.

Switching to lock-free atomic pointer swaps (arc-swap) eliminated reader blocking completely. Background route updates now clone the small routing index, apply the diff off the hot path, and atomically swap the pointer:

// Hot path: wait-free snapshot load, zero contention with writers
let routes = self.route_table.load();
let target = routes.match_host(host)?;

Memory overhead for keeping one previous generation alive while in-flight requests drain was under 14 MB for 1,400 hostnames. That single change cut p99.9 from 412.6 ms to 148.3 ms.

Finding 2: Upstream connection pool head-of-line stalls

Even with lock-free routing, p99.9 still sat at 148 ms. Flamegraphs pointed to something much less obvious: upstream connection reuse.

When an upstream worker restarted or closed an idle keep-alive socket right as our proxy wrote a new HTTP request onto it, Hyper returned a BrokenPipe / UnexpectedEof error. Our retry wrapper caught it and opened a fresh TCP connection, but two things made this expensive:

  1. Our idle timeout (90 seconds) was longer than the upstream's idle timeout (60 seconds), creating a 30-second window where the proxy routinely handed out half-closed sockets.
  2. A single global pool mutex serialized connection checkout across all 8 Tokio worker threads during traffic bursts.

We lowered the proxy's idle pool timeout to 45 seconds (safely below the upstream's 60-second window), enabled TCP keepalive probes, and sharded the upstream pool by worker core. Combined with an LRU cache for parsed leaf TLS certificates (avoiding repeated PEM parsing on cold SNI handshakes), p99.9 fell from 148.3 ms to 41.8 ms.

Finding 3: What did not matter as much as we thought

A few optimizations we tested produced negligible gains at our traffic profile and were reverted to keep the codebase simple:

  • Switching memory allocators (jemalloc vs system glibc malloc): Improved p99 by ~1.2 ms at the cost of a 19% increase in RSS. Not worth the memory tax on multi-tenant nodes.
  • Disabling Nagle's algorithm manually: Tokio/Hyper already set TCP_NODELAY on accepted sockets; redundant tuning changed nothing.
  • Pre-compressing every small response (< 1 KB): Added CPU overhead without reducing packet count because payloads already fit inside a single TCP segment.

Open questions

Our p99.9 is now consistently under 45 ms under 12k req/s with continuous deploy churn, which is a comfortable margin for interactive web apps. Two areas remain on our list for the next quarter:

  1. HTTP/3 (QUIC) migration jitter: Mobile clients switching between Wi-Fi and cellular show occasional 120 ms stalls during connection migration that we have not finished instrumenting.
  2. Noisy-neighbor TLS floods: A single misconfigured client opening 2,000 non-resumed TLS handshakes per second on one hostname can still nudge sibling tenants' p99 up by ~15 ms. Per-hostname handshake pacing is currently in staging.

If you run into unexplained latency spikes on your Weond deployments, send us the x-weond-ray response header — it maps directly to the edge node and timing breakdown we use in these traces.