Learn
Lesson · Capacity Estimation · Machines and memory

From a Request's Cost to a Machine Count

A machine’s capacity is one over what a request costs it, and the fleet is the peak divided by the capacity you are willing to use. Two things make this more than a division. The answer is a ceiling, because machines are integers and most of a machine will not serve anything. And the utilisation you divide by is a decision that has to be named: at 60% the fleet here is 167 machines, at 100% it is 100, and the difference is not a rounding.

capacity = 1 / (resource per request) = 8 cores · 1000 ms/s / 40 ms = 200 req/s per machine usable = capacity · ρ_target = 200 · 0.6 = 120 req/s N = ⌈peak / usable⌉ = ⌈20 000/120⌉ = ⌈500/3⌉ = 167 at N = 167 the peak sits at 100/167 = 59.88% of the fleet sized at ρ = 1 the same peak would have said N = 100
Capacity, headroom, and the integer that falls out

Core ideas

What this lesson establishes

One hard idea, the ceiling, with the two quantities it needs on either side of it: what a request costs, and how full you are willing to run.

1

Capacity per machine is one over the cost of a request

A request that occupies one core for 40 ms lets a machine with 8 cores serve 8 · 1000/40 = 200 requests a second. The general form is the same for any resource: capacity is the reciprocal of what one request consumes, in whatever unit is scarce. Choosing which resource is scarce is the modelling decision; the arithmetic after that is a reciprocal.

2

N is a ceiling, and the ceiling is the point

20 000 requests a second over 120 usable gives 500/3 machines, which is 166.67 and therefore 167. Machines come in whole numbers, so the exact fraction is never the answer — and rounding down for tidiness gives a fleet that is short at exactly the moment the peak arrives. The lab draws the staircase so the 2/3 of a machine at the top of the last tread is visible.

3

The headroom is named, and it is not an error bar

60% is a decision about how full a queue should be allowed to run, and it comes from queueing theory rather than from uncertainty about the inputs. It is taken as given on this course. “The Knee: Response Time vs Utilisation” is where it is earned, and the short version is that response time rises steeply as utilisation approaches one, so the last 40% of a machine buys latency you cannot pay for any other way.

The material

One request, one machine, one fleet

The reciprocal that gives a machine’s capacity, the target that reduces it, and the ceiling that turns the quotient into a fleet.

Definition · Capacity and target utilisation

The capacity of a machine is the reciprocal of the scarce resource one request consumes. Its target utilisation ρ is the fraction of that capacity the design is willing to use, so usable capacity is capacity · ρ. The machine count is N = ⌈peak / (capacity · ρ)⌉.

Every term has to be a peak or none of them can be. The rate going in is the peak rate from “Peak to Average”, not the mean; a fleet sized from a mean rate is short for as long as the busy period lasts, and no amount of care about the ceiling rescues it.

cores per machine 8 cost of one request 40 ms of one core capacity 8 · 1000 ms/s / 40 ms = 200 req/s target utilisation ρ 60% usable 200 · 0.6 = 120 req/s peak rate 20 000 req/s machines needed 20 000 / 120 = 500/3 = 166.67 N = ⌈500/3⌉ = 167 fleet capacity 167 · 200 = 33 400 req/s the peak sits at 20 000 / 33 400 = 100/167 = 59.88% spare 33 400 − 20 000 = 13 400 req/s

59.88% rather than 60% is the ceiling showing up in the answer: rounding 166.67 up to 167 bought two-thirds of a machine that nobody asked for, and the fleet is very slightly emptier than the target. That is the normal direction for this error to run, and it is the safe one.

Example · A checkout API at twenty thousand a second

Eight cores, 40 ms of one core per request, 60% target. Each machine serves 200 requests a second and is allowed 120, so the fleet is 167 machines carrying 33 400 requests a second of raw capacity, 13 400 of which is deliberately unused. Sized at 100% the same peak gives 100 machines, and the sixty-seven machines between those two answers are the headroom, priced.

What the sixty-seven machines buy

Not insurance against the estimate being wrong. The target utilisation is a queueing decision: as utilisation approaches one, waiting time rises without bound, and a fleet run at 95% has a latency profile that no amount of extra patience fixes. 60% is a point on that curve, chosen so that the response time is tolerable and a machine can be lost without the rest going over the knee.

The uncertainty in the inputs is a separate and multiplicative thing. If the peak rate and the per-request cost are each known to a factor of two, the ranges from “Orders of Magnitude” put the fleet somewhere across a ÷4 … ×4 interval, and the headroom does not begin to cover that. Two different questions, two different answers, and conflating them produces a fleet that is neither adequately provisioned nor honestly estimated.

An integer is not a precise answer

167 looks like a hard number and is only as hard as its inputs. Halve the per-request cost in the lab and the same peak and target give 84; double it and they give 334. Nothing about the ceiling makes 167 more certain than the 40 ms it came from — the ceiling removes the fractional part, not the range. The honest report names the fleet and the assumption that moves it most, which here is the cost of a request.

One constraint, and the case with two

This is the one-constraint version: the fleet is sized by request throughput and by nothing else. Real fleets are often held up by a second constraint at the same time — a data volume that will not fit, a connection count, a per-node write rate — and then the answer is the larger of the two ceilings rather than either one. “How Many Shards”, on Partitioning and Load Balancing, is that lesson: the same ceiling computed twice and a maximum taken. Doing the one-constraint case first is worth it, because the trap there is always to compute one ceiling and stop.

Interactive

From a request's cost to a machine count

An integer, with a headroom you have to name

From a request's cost to a machine countN = ⌈peak / (capacity × ρ)⌉, and the ceiling is the lesson
machines neededyour peak

Method

Turning a peak rate into a fleet

The scarce resource first, then a reciprocal, then a target, then a ceiling.

1

Decide which resource a request actually consumes

CPU milliseconds, memory, disk I/O, connections — one of them runs out first and it is the one to count. Getting this wrong produces a fleet sized by a resource that was never scarce, and the symptom is a system that falls over at a fraction of its computed capacity.

2

Turn the per-request cost into a per-machine capacity

Capacity is the reciprocal: cores × 1000 ms/s ÷ cost in ms for a CPU bound. Keep the units on the page — the 1000 ms/s row is the one people drop, and dropping it moves the answer by three orders of magnitude.

3

Multiply by the target utilisation, and say where it came from

ρ = 0.6 is a decision, not a measurement, and it belongs in the write-up next to the answer. An estimate that reports N without reporting ρ cannot be checked by anyone, because the two numbers are only meaningful together.

4

Divide the peak by the usable capacity and take the ceiling

⌈peak / usable⌉. Round up always: the fractional machine is doing real work at the peak, and the alternative is a fleet that is short for exactly as long as the busy hour lasts.

5

Report the fleet with the assumption that moves it most

Say what N is, what ρ was, and what the per-request cost was — and then say what N would be if that cost were half or double. The integer looks exact and inherits every range that went into it.

Capacity, headroom and the ceiling

Score 0 / 0

20 000 req/s at 40 ms of one core, 8 cores, 60% target

Four inputs, one reciprocal, one ceiling, and a comparison against the answer that skips the headroom.

peak rate 20 000 req/s from the profile cost of one request 40 ms of one core cores per machine 8 target utilisation ρ 60% capacity per machine 8 cores × 1000 ms/s / 40 ms = 200 req/s usable at the target 200 × 0.6 = 120 req/s machines needed 20 000 / 120 = 500/3 = 166.67 N ⌈500/3⌉ = 167 fleet raw capacity 167 × 200 = 33 400 req/s peak as a fraction 20 000 / 33 400 = 100/167 = 59.88% spare at the peak 33 400 − 20 000 = 13 400 req/s sized at ρ = 1 ⌈20 000 / 200⌉ = 100 the headroom costs 167 − 100 = 67 machines cost halved to 20 ms capacity 400, usable 240 = N = 84 cost doubled to 80 ms capacity 100, usable 60 = N = 334

The two lines at the bottom are the ones that stop 167 from looking like a measurement. The per-request cost is a ranged factor like every other input on this course, and a factor of two in it is very nearly a factor of two in the fleet. The ceiling removed the fraction; it did not remove the range.

The 59.88% is worth noticing too. The target was 60% and the fleet runs just under it, because the ceiling handed you two-thirds of a machine you had not asked for. Over-provisioning by a fraction of a machine is the correct direction for that error, and it is the direction the ceiling always errs in.

For a faded rehearsal, take the lab’s edge-cache example: 500 000 requests a second, 2 ms a request, 4 cores, 80% target. The supplied first move is the capacity, 4 · 1000/2 = 2 000 requests a second per machine. Produce the usable capacity, the exact machine count and N, then predict what N becomes at a 60% target before changing the slider.

Common mistakes

1
Sizing the fleet at a hundred percent of capacity⌈20 000/200⌉ = 100 machines is arithmetically correct and describes a fleet with no room for a deploy, a failed machine or a bad afternoon, running at the part of the queueing curve where response time climbs fastest. The same peak at a 60% target needs 167. The sixty-seven machines are not waste; they are the latency the design asked for, and they should be reported as such.
2
Treating the headroom as cover for a wrong estimateThe 60% answers “how full should a queue run” and the ranges answer “how well do we know the inputs”, and they compose by multiplying rather than one absorbing the other. A peak known to ±2× and a cost known to ±2× put N across a ÷4 … ×4 interval; a target of 60% covers a factor of well under two. Anyone relying on the headroom to absorb the estimate has covered neither.
3
Reading the integer as a precise answer167 is a ceiling of an exact fraction, which makes it exact given its inputs and no better known than they are. In the lab, halving the per-request cost gives 84 and doubling it gives 334 — the same peak, the same target, three fleets. The ceiling is the last step of the arithmetic and it is not a promotion from estimate to measurement.

Check your understanding

✓
Finish when a machine count quoted without its target utilisation reads as an unfinished answer.

You should be able to turn a peak rate, a per-request cost and a target into N without assistance, say why the answer is a ceiling and never a rounding, distinguish the headroom from the uncertainty in the inputs, and name what N becomes if the per-request cost is out by a factor of two.

Note: Machines are counted; memory is not counted the same way. “Memory and the Working Set” is the last of the four things a rate sizes, and it is the one where the whole dataset is the wrong denominator — a cache is sized to the fraction of the data the traffic actually touches, and the curve relating that fraction to the hit rate has a knee in it that decides the budget.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.