Skip to main content

29 posts tagged with "Performance"

Throughput, latency, and scaling in distributed systems.

View All Tags

Your p99 Is Lying: Coordinated Omission in Latency Benchmarks

· 11 min read
Clustron Team
Distributed Systems Engineering

Here is a result that should make you suspicious of every latency benchmark you have ever trusted. A load generator pushes ten thousand requests per second at a cache, records the latency of each, and reports a p99 of two milliseconds and a p99.9 of four. The numbers are stable across runs. The SLA asks for ten milliseconds at p99, so there is comfortable margin. The change ships. In production, at the very same throughput, the p99 is two hundred milliseconds and the pager goes off.

Nothing about the server changed between the benchmark and production. What changed is that the benchmark was allowed to look away at the exact moment the latency happened. The generator was closed-loop: it sent a request, waited for the response, and only then sent the next one. That one design choice — wait for the reply before issuing the next request — is enough to delete almost the entire tail from the measurement, and it does so in a way that gets worse the worse the stall is.

The name for this is coordinated omission, a term Gil Tene gave it, and the word coordinated is the whole insight: the system under test quietly coordinates with the measurement system, pausing the measurer at precisely the moments the measurer most needs to be taking samples. The requests that go missing are not a random sample of the workload. They are the slow ones, and they go missing because they would have been slow.

Everybody Retries at Once: Backoff, Jitter, and the Synchronized Herd

· 10 min read
Clustron Team
Distributed Systems Engineering

Here is a failure that looks like a capacity problem and is really a timing problem. A node is briefly unavailable — it restarted, it paused, a switch dropped a link for a moment — and a large population of clients all receive an error within the same narrow window. Each client is well-behaved: it waits a moment and retries, and if the retry fails it waits longer and retries again, doubling the delay each time. This is exponential backoff, it is the textbook answer, and on its own it is not enough.

The trouble is that every client in that population failed at the same time and is running the same backoff schedule, so they do not just retry — they retry in unison. One second after the blip, all thousand clients retry at once. If that wave fails or the node is still warming up, two seconds later all thousand retry again, together. The backoff is working in the sense that each client is making fewer attempts over time, but the attempts are stacked into synchronized spikes, and a spike of a thousand simultaneous requests against a node that just came back is often enough to knock it down again. The herd never disperses; it just arrives less often, in the same tight clump.

That clump is the whole problem, and it is why backoff without jitter can turn a half-second blip into a rolling outage. The clients have accidentally formed a distributed clock, all ticking in phase, and every tick lands on the same target at the same moment. What you want instead is for the same total number of retries to arrive spread out — a steady trickle the recovering node can absorb rather than a wall it cannot. The way you get there is to deliberately desynchronize the clients, and the tool for that is jitter.

The Cheapest Way to Say No: Bloom Filters and the Negative Lookup

· 12 min read
Clustron Team
Distributed Systems Engineering

Caches are built to make the common case — the key is present — fast, and they do. What they handle badly, almost by construction, is the key that is absent. A request arrives for a key that does not exist: a user id that was never registered, a product that was removed, a session that expired and was swept. The cache has no entry, so it misses. The miss falls through to the database, which does the full work of looking and finds nothing. And now you are stuck, because there is nothing to put in the cache — the key has no value to store — so the very next request for that same non-existent key repeats the entire round trip.

It gets worse when the absent keys are not the same key repeated but a stream of distinct non-existent keys: a crawler walking ids, a bug generating bad references, or simply a sparse keyspace where most possible keys were never used. Each distinct miss penetrates the cache exactly once and lands on the database, and because they are all different, nothing you could cache would stop the next one. This is cache penetration, and it is the failure mode where a cache not only fails to help but actively adds a hop to every doomed lookup on its way to crushing the database behind it.

What you want is a way to know a key is absent without asking the database — a gatekeeper that sits in front of the real lookup and, for keys that definitely do not exist, returns "not found" immediately. The catch is that a structure holding every key that does exist, so it can answer by exclusion, would be nearly as large as the dataset itself, which defeats the purpose. A Bloom filter is the structure that escapes this bind: it answers "is this key definitely absent?" using a few bits per key, by accepting a small, controllable chance of being wrong in the one direction that is safe to be wrong in.

Racing the Tail: Hedged Requests and When to Send a Second Copy

· 10 min read
Clustron Team
Distributed Systems Engineering

Here is a latency fact that does not go away no matter how fast you make the common case. Every replica in a cluster occasionally stalls — a garbage-collection pause, a compaction, a page fault, a few hundred microseconds sharing a core with a noisy neighbor. For any single request the odds of hitting one of these are small, so the median is beautiful. But the stalls are frequent enough to show up at the ninety-ninth percentile, and the ninety-ninth percentile is often the number in the SLA.

It gets sharper the moment one user action needs more than one request. If a page assembles from twenty reads and each read independently has a 1% chance of landing on a stalled replica, the chance that at least one of the twenty is slow is not 1% — it is about 18%. The slowest of the twenty sets the response time, so the tail you occasionally saw on one request becomes the tail you routinely see on the whole page. You cannot fix this by making the fast path faster; the fast path was never the problem. The problem is the straggler, and the straggler is somewhere different every time.

Hedging attacks the straggler directly, and it does so without knowing in advance which replica will be slow. The idea: send the request to one replica, and if it has not responded by the time it is already running late — say, by its own p95 — send a second copy of the request to a different replica, then take whichever response arrives first and ignore the other. You are not retrying a failure; the first request has not failed, it is merely slow, and you are refusing to wait on it when a fresh copy against a different replica will very likely beat it.

Head-of-Line Blocking: When One Slow Request Stalls Everyone Behind It

· 10 min read
Clustron Team
Distributed Systems Engineering

Picture a single line at a counter. Most people have a quick errand — a stamp, a question — that takes seconds. Then one person steps up with a complicated transaction that takes ten minutes, and everyone behind them, no matter how trivial their errand, waits ten minutes. The counter is not overwhelmed; it is serving someone the entire time. The queue is simply ordered, and the slow item is at the front. That is head-of-line blocking, and almost every layer of a distributed system has a version of this line hidden in it.

The reason it is such a reliable source of confusing latency is that it decouples how busy a resource is from how long requests wait. A saturated server is easy to diagnose — CPU pinned, queues deep, everything slow in proportion. Head-of-line blocking produces the opposite signature: the server is nearly idle, most requests are instant, and a subset of requests — the ones that happened to arrive behind a straggler — are wildly slow, with no correlation to what they themselves were doing. You go looking for the expensive query that must be causing the spike, and the slow request is a one-key GET that should have been free.

What makes it worse is that the two reflexes you reach for both miss. Adding capacity assumes the resource is the bottleneck, but the resource was idle — it was blocked, not busy. Optimizing average latency assumes the slow requests are intrinsically slow, but they were fast; they inherited the latency of the item in front of them. The problem is not throughput and it is not per-request speed. It is ordering, and you fix it by changing the order, not the speed.

The Load Went Away and It's Still Down: Metastable Failure

· 11 min read
Clustron Team
Distributed Systems Engineering

Most outages have the decency to end when their cause ends. The dependency comes back, the spike subsides, the bad deploy is rolled back, and the system returns to normal on its own. You can draw a straight line from cause to effect and back again. The failure that does not play by those rules — the one that keeps senior engineers up arguing about why the graphs will not move — is the one where the cause is long gone and the system is still face-down on the floor.

The shape is always the same. The system is running fine, comfortably under capacity. Some trigger arrives: a burst of traffic, a few seconds of dependency latency, a cold cache after a deploy, a node restart that briefly halves capacity. For a moment the system is overloaded, which by itself is survivable. But in that moment a feedback loop engages — and once it engages, it supplies its own fuel. The trigger passes, offered load drops back to the ordinary level the system was handling an hour ago, and goodput stays near zero. The system has fallen into a second stable state: overloaded, serving almost nothing, and perfectly content to stay there.

That is a metastable failure, and the word "stable" is the important half. The collapsed state is not a transient on its way back to health; it is an equilibrium the system will hold indefinitely until something external breaks the loop. This post is about why a system can have two equilibria instead of one, why the bad one sustains itself, and what actually gets you out.

The Tail at Scale: Why p99 Becomes p50 When You Fan Out

· 10 min read
Clustron Team
Distributed Systems Engineering

Profile a single shard and the latency looks healthy. Say the median response is two milliseconds and the 99th percentile is twenty — one request in a hundred is slow, the rest are quick, and that is a perfectly ordinary, perfectly acceptable distribution. You would ship it without a second thought. The trouble starts when you stop sending one request at a time and start sending requests that fan out: a scatter-gather across partitions, a multi-key read whose keys live on different shards, a search that must consult every slot. A request like that cannot return until every branch has answered, and that single fact changes everything about the latency you actually experience.

Here is the arithmetic that catches people off guard. A fan-out request is as slow as its slowest branch, and the slowest of many samples comes from the tail of the distribution, not its center. If each branch is independently slow with probability one percent, the chance that at least one of a hundred branches is slow is one minus ninety-nine-hundredths to the hundredth power — about sixty-three percent. So almost two out of every three wide requests will contain at least one slow branch, and because you wait for all of them, that branch sets the clock. The twenty-millisecond tail you dismissed as a one-percent event is now the typical latency of your fan-out request. This is what Dean and Barroso named "the tail at scale."

The instinct when latency is bad is to make things faster on average — cache more, serialize less, tighten the hot path. For a fan-out request that instinct is almost entirely wasted effort, because the request does not care about your average; it cares about your tail, and the two can move independently. This post is about why that is, and what actually works instead.

The Thundering Herd: Turning N Cache Misses Back Into One

· 10 min read
Clustron Team
Distributed Systems Engineering

Caching works by arithmetic. A value that costs 200 milliseconds and a heavy database query to compute gets stored under a key, and for the next ten minutes every request for it is served from memory in microseconds without touching the database at all. If that key sees ten thousand requests a second, the cache is absorbing ten thousand requests a second and the database is seeing, effectively, none. That ratio — the whole point of the cache — is also exactly what makes its failure mode so violent.

Because the ten minutes end. The key expires, and in the microsecond after it does, the ten thousand requests per second that were all being served from that one cached value all miss, simultaneously. Each of those requests, finding nothing in the cache, does the natural thing: it recomputes the value — runs the heavy query, hits the backend. So the backend that was sized for the cache-protected load, perhaps a handful of queries a second, is suddenly handed ten thousand identical expensive queries in the same instant. It does not serve them faster for their being identical. It saturates, queues, and falls over, and the cache miss you thought was a microsecond of latency has become a full outage of the system the cache existed to protect.

This is the cache stampede — the thundering herd, the dogpile — and it has a nasty self-sustaining quality: while the herd is all recomputing, the key is still empty, so every new request that arrives also misses and joins the herd. The stampede feeds itself until the backend dies or the herd drains. The fix is not a bigger backend, because any backend can be swamped by a hot enough key. The fix is to stop letting N misses each act as if they were alone.

Saying No on Time: Backpressure and Bounded Queues Under Overload

· 10 min read
Clustron Team
Distributed Systems Engineering

Every server has a rate it can sustain — some number of operations per second it can actually complete — and sooner or later something will ask it for more. A traffic spike, a thundering-herd retry storm, a batch job someone kicked off at the wrong time: the arrival rate climbs above the service rate, and now the system has a decision to make. Not a decision it makes consciously, but one baked into its design, and the one that decides whether a brief overload is a blip or an outage.

The tempting answer is to accept everything and queue what you cannot serve yet. It feels like the responsible, graceful choice — nothing is rejected, every request is honored eventually, the overload is just smoothed out over time. For a short burst against spare capacity, that is exactly right, and a queue is precisely the shock absorber you want. The trap is the word unbounded. If the queue has no limit and the overload is not brief, you have not smoothed anything — you have built a machine that converts sustained excess load into unbounded latency and then, reliably, into an out-of-memory crash. The system stays nominally "up," accepting requests, right up until it falls over all at once.

A store that survives overload is built on the opposite instinct: bound every queue, make the server push back when it is full, and answer an immediate, honest "busy" rather than quietly swallowing work it cannot finish in time. This post is about why that is the stable choice, and why a fast no is a kindness.

The Hot Key Problem: When One Shard Does All the Work

· 11 min read
Clustron Team
Distributed Systems Engineering

The appeal of a sharded data store is a clean scaling story. Partition the keyspace across N shards, send each key to its owner, and the work spreads out: each shard carries roughly a fraction of the total, latency stays flat as the dataset grows, and when you run short of capacity you add shards and the fraction shrinks again. It is one of the most reliable patterns in distributed systems, and for a great many workloads it simply works. But the whole story rests on one assumption that is easy to state and easy to forget: it spreads the load evenly only if every key is touched about equally often.

Real workloads are nothing like that. Access frequency across keys is almost always heavily skewed — a small handful of keys absorb the overwhelming majority of the traffic while the long tail is nearly idle. A single celebrity's profile, the view counter on a post that just went viral, a global configuration key every request reads, the top entry of a leaderboard: each is one key, drawing enormous fan-in. And because partitioning sends a given key to exactly one shard, all of that traffic lands on exactly one shard. That shard saturates — pinned at 100%, queuing, shedding, p99 climbing — while its neighbors twiddle their thumbs.

What makes the hot key genuinely nasty, rather than merely annoying, is that the usual instincts make it worse. The cluster's average utilization looks fine, so capacity planning says there is headroom. Adding nodes lowers the average further and leaves the hot shard exactly where it was, because the hot key does not relocate when you scale out. You cannot add your way out of a hot key. This post is about why that happens and what actually does work.