Sizing and TCO

ch07 · When adding servers stops helping

Builds on ch06.

A video summary of this chapter, generated from the page by an AI tool (how it was made). The page is the authority; the video needs a network connection.

The question

How far does a system scale, and how would you find out from the three measurements you have?

ch06 ended with a fleet too close to its margin and an obvious remedy: buy more machines. This chapter is about how much less that buys than the arithmetic promises. It is also about the count past which each new machine takes capacity away.

The material

Two costs, and only one of them is famous

Machines do not add up, and there are two separate reasons.

Contention. Some fraction of the work cannot be done in parallel: a lock, a single writer, a shared queue, a coordinator. That fraction takes a fixed share of every machine you add, so the cost grows with the count of machines and the curve flattens. This is the well-known one of the two costs: Amdahl’s argument [Amdahl (1967)]. With contention alone, throughput approaches a limit as machines are added and never reaches it, so the curve never turns down.

Crosstalk. Machines have to agree with each other. Every new one has to be told about all the others, so the cost grows with the number of pairs, not the number of machines. Ten machines make forty-five pairs. Twenty make a hundred and ninety. Doubling the fleet did not double the agreeing; it roughly quadrupled it.

Crosstalk does something contention never does. Contention flattens the curve. Crosstalk turns it over. Past some count, the next machine costs more in agreement than it brings in work, and the total goes down.

Both terms together are the universal scalability law [Gunther (2008)]:

  linear_throughput:
    kind: derived
    unit: request/second
    label: throughput if scaling were free
    formula: hosts * single_host_throughput
  achievable_throughput:
    kind: derived
    unit: request/second
    label: achievable throughput
    note: >-
      The universal scalability law. One host's throughput times
      the host count, divided by what contention and crosstalk
      take back. With crosstalk at zero, it approaches Amdahl's
      limit and never falls; with both at zero, it is `linear_throughput`:
      the straight line.
    formula: linear_throughput / (1 + contention * (host_count - 1) + crosstalk * host_count * (host_count - 1))

The curve, against the straight line

The dashed line is what a budget assumes. The solid one is what the machines do. They separate almost immediately. The dashed line leaves the top of the figure while the real curve is still climbing slowly, and then the real curve stops climbing.

HostsThroughputIf scaling were freeEfficiencyPer host
22,4312,44899%1,215.5
44,7944,89698%1,198.5
89,3209,79295%1,165.0
1617,59819,58490%1,099.9
3231,29739,16880%978.0
6449,41778,33763%772.1
9658,924117,50550%613.8
12863,216156,67340%493.9
160 peak64,468195,84133%402.9
20063,701244,80226%318.5
25660,636313,34619%236.9
32056,246391,68314%175.8
40050,830489,60410%127.1
swept peak160 hosts, against 164.4 predicted from the two coefficients

Source — scaling-curve · sizing.evaluate

The Throughput column rises to the row marked peak, then falls in every row after it. Past the peak, the next machine contributes less than nothing. The machines added took away more throughput than they brought. The Per host column is the fleet’s throughput divided by its host count: the average over every machine in the fleet, not what the last machine alone added. Per host falls in every row but never goes below zero, even past the peak, so the drop shows in the Throughput column instead.

The last row gives the peak twice: one figure from sweeping the host count through the table and taking the largest throughput, and another from the two coefficients alone. The two are computed independently, and they agree to within the spacing of the sweep. The swept peak can only land on a row of the table. The closed form in problem 7.3 lets you find the peak without sweeping through the curve.

The utilisation you were quoted was optimistic

ch06 had no scaling term, so its utilisation was the work arriving divided by what the machines could do if each of them worked alone. They do not work alone. Some of their capacity is spent on each other, and utilisation, counting coordination divides the arriving work by what the fleet can deliver.

The model carries both numbers, side by side, on purpose:

  utilisation_including_coordination:
    kind: derived
    unit: dimensionless
    label: utilisation, counting coordination
    note: >-
      The same fleet's utilisation, worked out from what it can
      deliver rather than from what its hosts could deliver alone.
      It is higher than `utilisation` whenever the fleet has more
      than one host, and equal at one host. The gap is the work
      the hosts do on each other's behalf.
    formula: peak_request_rate / achievable_throughput

The table at the start of the next section prints both utilisations: the queueing view and the one that counts coordination. Compare the two in the first column to see the gap between them for the fleet as it stands. The queueing view is not wrong. It is optimistic, and you do not see how much until you measure the fleet at two sizes and find the larger one delivers less than the arithmetic promised.

What doubling buys

OutputReference scenarioTwice the hostsRatio
hosts in the fleet541082.00
throughput if scaling were free (request/second)66,096132,1932.00
achievable throughput (request/second)44,87661,0051.36
scaling efficiency0.6790.4610.68
utilisation0.6440.3220.50
utilisation, counting coordination0.9480.6980.74
time spent queueing (second)0.02360.00620.26
where adding hosts stops helping1641641.00

Source — web_service-reference and web_service-twice_the_hosts · the model to explore; each input with a range has a slider

The table compares the fleet as it stands with the same workload on twice the hosts, with everything else unchanged. The Ratio column divides the second by the first. Hosts in the fleet and throughput if scaling were free both double. The straight line is one host’s throughput times the count. Achievable throughput rises much less than double, so scaling efficiency falls. It is throughput divided by the straight line: its Ratio is throughput’s halved.

Utilisation halves: the same busy cores divided by twice the cores, and it is the queueing figure from ch06, which does not count coordination. Utilisation, counting coordination falls by much less than half, as it divides the arriving work by what the fleet delivers, which rose by less than double. Time spent queueing falls by more than half because the calculation uses the optimistic utilisation and ch06’s non-linear division, which works in your favour in this direction. Where adding hosts stops helping does not move, as it depends on the two coefficients, not on fleet size.

CeilingAt the planHeadroomAllowedLimitVerdictOver allowedOver limit
utilisation at the busy hour0.6430%0.701.00ok46%30%
utilisation, counting coordination0.9530%0.701.00into the margin65%48%
fraction of the fleet doing nothing useful0.3250%0.501.00ok1%0%

Source — web_service-reference · the model to explore; each input with a range has a slider

CeilingAt the planHeadroomAllowedLimitVerdictOver allowedOver limit
utilisation at the busy hour0.3230%0.701.00ok17%8%
utilisation, counting coordination0.7030%0.701.00ok52%35%
fraction of the fleet doing nothing useful0.5450%0.501.00into the margin72%0%

Source — web_service-twice_the_hosts · the model to explore; each input with a range has a slider

The next two tables show ch06’s ceilings table for the fleet as it stands and for twice the hosts. They hold the ceiling ch06 introduced and the two this chapter adds. For both utilisation ceilings, the shares of futures past the allowed line and past the limit fall when the fleet doubles, as the Over allowed and Over limit columns show. Fraction of the fleet doing nothing useful has a limit of one. A fleet cannot waste more than all of its work, so it never passes its limit; read its allowed line instead. That row moves the opposite way when the fleet doubles: its value rises, its verdict worsens, and the share of futures past the allowed line rises. This ceiling protects a budget, not latency. Nothing fails and nobody is paged, and a fleet past its allowed line is paying for hosts whose work goes to coordination and contention rather than to requests.

Doubling a fleet buys lower queueing time, by the optimistic measure, and little extra capacity. These are different purchases. A request for more hosts does not say which it is buying; the table shows them as separate rows so you can see which you are getting. The graph below has sliders for contention and crosstalk.

The graph as ch07 leaves it. Two ceilings arrived with it: one on what the fleet spends on itself, one on the utilisation the queueing view understated.

Fitting the coefficients from what you have

Measuring the fleet at more than one size is also how you fit the coefficients. The law has three unknowns: one host’s throughput, contention and crosstalk. Three measurements at three different host counts determine them exactly. You will usually have three: one machine on a bench, the fleet you run now, and the fleet you ran before you grew it. That is not much data, and it is what exists.

Problem 7.2 is the algebra. Do it by hand once. Rearranging the law into a straight line shows why three points are the minimum and why they must be at different counts. Two measurements at the same count tell you no more than one of them.

Then notice what you have done. You have extended a curve with three numbers in it out to hundreds of machines, from three points clustered at the low end, and you are about to spend money on the extrapolation. The coefficients in this book’s model are not fitted. They are assumptions, and their provenance says so.

The shape is the claim. The position of the peak is a guess.

What this cannot tell you

Where your peak is. The coefficients here are assumptions, and the peak follows from them. The size of the fleet does not move the peak. The doubling table showed where adding hosts stops helping unchanged when the hosts doubled. Drag crosstalk in the graph above and watch where adding hosts stops helping move. Fitting the coefficients from three measurements gives numbers with the same problem and a false air of precision. What transfers is that a peak exists, and that it is a property of the software.

Whether the coefficients are stable. Coefficients fitted from measurements describe one kind of work over a narrow range of fleet sizes. The three points are at different counts, but they sit close together at the low end of the curve. A different workload mix has a different serial fraction, so a different contention. A version that adds a coordination round has different crosstalk. A curve fitted last year describes last year’s software.

What queueing costs a fleet that coordinates. This model’s queue does not see coordination. Residence time and time spent queueing are computed from utilisation, the figure that divides by what each host could do alone. No node computes a queueing time from utilisation counting coordination, in this chapter’s model or in the finished one. So every latency figure on this page, the doubling table’s included, is the optimistic one, and the model cannot say by how much.

What to do about it. The law says where scaling stops paying. It has nothing to say about which lock to remove, and removing the lock changes the coefficients in a way only another measurement can establish.

Anything about failure. Every figure above is a healthy fleet. Machines coordinating while one of them is unreachable behave differently and worse, and this model has no term for it. ch11 is where that gets a margin rather than a model.

Whether the fleet is even the constraint. The whole chapter assumes throughput is what you are buying. If the system is bounded by something else, a database, a licence or a single-threaded step, the curve above describes a queue in front of the real problem.

Key takeaways

  • Machines do not add up, for two separate reasons. Contention takes a fixed share of every machine you add and flattens the curve. Crosstalk grows with the number of pairs and turns the curve over.

  • Past the peak, the next machine takes capacity away. Each machine adds less throughput than the one before it. After the peak, the next machine adds less than nothing and the total falls.

  • Doubling the fleet cuts queueing time and buys little capacity. Throughput rises by much less than double, and efficiency falls. Time spent queueing falls by more than half, but the model computes it from the utilisation that ignores coordination, so that gain is the optimistic one. Those are different purchases.

  • The utilisation a queueing view quotes is optimistic. Some of every machine’s capacity is spent on the others, so the figure that counts coordination divides by what the fleet can deliver.

  • The shape of the curve is the claim. The position of the peak is a guess. Three measurements at different sizes fit the coefficients exactly, and extrapolating them to hundreds of machines is the bet you are placing.

Problems

Four, in tests/when_adding_servers_stops_helping/. The first three have tests. The last does not.

7.1 — Write the law. Two terms in the denominator, behaving differently. The tests check that contention alone flattens the curve and that with crosstalk added the curve turns over, so the two cannot stand in for each other.

tests/when_adding_servers_stops_helping/stubs.py · throughputyours to edit
def throughput(
    hosts: np.ndarray | float, one_host: float, contention: float, crosstalk: float
) -> np.ndarray:
    """Problem 7.1 - the scalability law, written out.

    ``one_host`` is what a single machine achieves alone. ``contention`` is the fraction of the
    work that cannot be done in parallel. ``crosstalk`` is the cost of machines having to agree
    with each other. Return the throughput of ``hosts`` machines.

    The denominator has two terms and they behave differently:

    * contention costs a fixed share of every machine you add - it grows with the *count*, and it
      flattens the curve;
    * crosstalk is machines coordinating with each other, so it grows with the number of *pairs* -
      and it is what makes the curve turn over and come back down.

    The tests check each one's behaviour on its own: contention alone must flatten the curve,
    and with crosstalk added the curve turns over, so the two cannot stand in for each other.

    With crosstalk at zero the curve approaches a limit and never falls: Amdahl's limit. With
    both at zero you have the straight line nobody has ever measured.

    The test checks it against the sweep the book publishes, at every host count, so it has to
    be the model's formula and not one that is close near the middle.
    """
    raise NotImplementedError("problem 7.1")

The same check at a desk: python3 -m pytest tests/when_adding_servers_stops_helping/test_problem_1_law.py -m problem

7.2 — Fit it from three measurements. Rearrange the law until it is linear, then solve. Write the rearrangement down before you code it. The function returns all three unknowns: one host’s throughput, contention and crosstalk.

tests/when_adding_servers_stops_helping/stubs.py · fityours to edit
def fit(measurements: list[tuple[float, float]]) -> tuple[float, float, float]:
    """Problem 7.2 - the law's three numbers, from measurements you can take.

    ``measurements`` is a list of ``(hosts, throughput)`` pairs. You will usually have three: one
    machine, the fleet you have, and the fleet you had before you grew it. That is not much
    data and it is what exists.

    Return ``(one_host, contention, crosstalk)``.

    Three unknowns, so three measurements determine them exactly - solve, do not optimise. With
    the one-machine measurement in hand, ``one_host`` falls straight out, and the remaining two
    come from two linear equations once you rearrange the law to put the denominator on the other
    side. Write the rearrangement down before you code it; it shows why the three points must be
    at different counts.

    Then notice what you have done. You have extended a curve with three numbers in it to hundreds
    of machines, from three points clustered at the low end. The chapter's section on fitting says
    what that is worth.
    """
    raise NotImplementedError("problem 7.2")

The same check at a desk: python3 -m pytest tests/when_adding_servers_stops_helping/test_problem_2_fit.py -m problem

7.3 — Find the peak. Differentiate and set to zero. It comes out as a square root, and it says the peak belongs to the software rather than to the budget. Handle zero crosstalk: with no coordination cost the curve never turns over, so there is no peak. Raise ValueError, or return an infinity. A large number is not the same answer.

tests/when_adding_servers_stops_helping/stubs.py · peak_hostsyours to edit
def peak_hosts(contention: float, crosstalk: float) -> float:
    """Problem 7.3 - where adding machines stops helping.

    Return the host count at which throughput is greatest, from the two coefficients alone.

    Differentiate your answer to 7.1 with respect to the host count and set it to zero. It comes
    out as a square root. It says the peak is a property of the software - of how much it
    serialises and how much it coordinates - and that no budget moves it.

    Handle zero crosstalk. With no coordination cost the curve never turns over and there is no
    peak. Raise ``ValueError``, or return an infinity (``math.inf`` or ``float("inf")``). A large
    number is not the same answer, and nor is letting the division fail: the test fails a
    ``ZeroDivisionError``.
    """
    raise NotImplementedError("problem 7.3")

The same check at a desk: python3 -m pytest tests/when_adding_servers_stops_helping/test_problem_3_peak.py -m problem

7.4 — The time adding machines did not help. No test: the measurements are your fleet’s, and this repository has none of them.

Somewhere in your organisation there is a tier that got a bigger fleet and did not get proportionally faster. Find its throughput at two fleet sizes, and a single machine’s on a bench. Those are the three measurements the chapter says you usually have.

Put them through the rearrangement you wrote for 7.2: by hand, or by calling your fit at a desk. The Check on this page runs the book’s test cases, not your numbers. Then use 7.3 to write down where the peak comes out.

With no bench figure you have two measurements and three unknowns, and the law cannot be fitted. You can still work out throughput per host at each fleet size and say whether it fell as the fleet grew. If it fell, something is costing you, but you cannot tell which cost or where the peak is. Say that, and say the missing measurement is one machine on a bench under the same load.

Then write down which of this chapter’s two costs the numbers point at: contention for something shared, or the cost of machines agreeing with each other. If the fit says neither, you have found a third mechanism. A good answer names the tier, the fleet sizes and their throughputs, the peak the fit implies, and why you would not spend money on that peak. If you cannot find throughput at two sizes, that is an answer too. It means nobody measured throughput per host when the fleet grew, and the next growth is the chance to.

Where to go next

Gunther’s paper [Gunther (2008)] derives the law from a queueing argument rather than by fitting a curve to data. Read it if the crosstalk term has so far felt like a free parameter.

ch08 is what this chapter and the last one have in common: a point where the chain of multiplications stops describing the system, and no care over the inputs would have warned you.

By Chris Snow, in collaboration with Claude (Anthropic) · Prose and figures: CC BY-NC 4.0 · Code and models: Apache 2.0