Back to blog

Is your server slow, or is it just busy?

Thắng Đoàn
Thắng Đoàn

FotoFlow has 500 users now, and the one server is at 70 percent busy at dinner time. Before you buy anything, you need to know which question you are answering: are individual requests slow, or is the machine simply full?

Two different questions

Latency is how long one request takes. Throughput is how many you finish per second. Think of a highway: latency is how long your drive takes, throughput is how many cars pass per hour. Extra lanes let more cars through, but on an empty road they do not get you there any sooner. If users complain things are slow, that is latency. If the server refuses work, that is throughput.

Busy servers slow down before they are full

Here is the trap. Traffic grows a bit more and the server hits 96 percent busy. Throughput barely moves, a whisker under its ceiling of 500 requests per second. But the queue in front of the server explodes, and latency jumps sevenfold.

Requests do not arrive evenly spaced. With 30 percent spare capacity, a burst is absorbed quickly. With 4 percent spare, every burst piles up behind requests already waiting, and the line takes ages to clear. Latency grows slowly, then suddenly. Plan to run at 60 to 70 percent busy at peak.

The fix for latency under load is not a faster server, it is lower utilization: more capacity, or less work per request. Doubling the cores takes the same load to 35 percent busy, the queue drains, and both the typical and the slow requests speed up.

The average lies; look at p99

Back at 70 percent busy, most requests are quick but a few get stuck behind slow work. The average, about 180 ms, looks healthy because it blends the pain away. So we measure percentiles instead: p50 is the time half of requests beat, p99 is the time only 1 in 100 exceeds.

Averages hide the pain. Watch p99, because the tail is what users feel. A page that fires 30 requests hits the p99 on about one load in four. Fan-out makes it worse: a search that asks 100 servers in parallel must wait for the slowest, so a rare tail on one machine becomes the common case for the whole page.

Distance and in-flight work

Move the server across an ocean and nothing on it got slower, yet every round trip takes 75 ms or more. Light in fiber covers about 200 km per millisecond. No server upgrade beats physics. Distance sets a floor on latency.

One small rule ties the numbers together: requests in flight equal throughput times latency. At 350 requests per second and 0.12 s each, about 42 requests are being worked on at any moment, each holding a thread or a connection. If latency rises to 1 second, 350 are in flight and pools sized for 50 run dry. That is why one slow dependency can take down a whole server.

What this does not solve

Naming latency versus throughput does not tell you which one FotoFlow lacks, and it does not shrink distance. Cutting the tail needs capacity or caching, and cutting distance needs content closer to users, each covered later in the series.

If your p99 is 10 times your p50, is your system slow for everyone, or slow for a specific unlucky slice?
When you last added capacity, did latency actually drop, or did you just buy headroom you had not measured?

Slow and busy are different diseases. Diagnose before you pay.

Next in the series: Can you size your servers on the back of a napkin?

Sources

System Design Primer

Designing Data-Intensive Applications

undefined

Google SRE Books

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

No pasting. This is the challenge.0/200

Typed live, never pasted.