Sizing and TCO

Appendix A · The DSL, in full

A model is a YAML file. It declares named quantities, each with a unit, and how they depend on each other. There is no evaluation order in the file, no cells, no hidden state, and no way to write a number in one place and have it mean something else in another.

Every key in a model file or scenario file is on this page, along with what happens when you leave it out; so is every rule the build applies. The unit names are in Appendix D. The language is small on purpose: a model somebody has to learn a system to read is a model nobody reads.

The file

dsl: 2
model: web_service
title: A web service and its data, on a fleet of Linux hosts
currency: USD

description: >-
  The book's running example: a service that takes requests and keeps records, run on some
  number of ordinary hosts, sized from a stated workload and costed over five years. Requests
  arrive and data accumulates; a host has cores, memory and disk, and each of those is a chain
  that ends in a count of hosts. One of the three binds.

  It is a conditional model. Its ceilings are: the queueing margin at the busy hour; the point
  where more hosts stop helping; the working set outgrowing memory; disk filling; and a host lost
  at the busy hour. Its one measured constant is how well the stored records compress. Its one
  rate constant — CPU time per request — belongs on a rig nobody has declared, and is held as a
  labelled claim until one is.

  Vendor-neutral by construction. Nothing below names a product; every figure is a workload
  assumption, a price you would get quoted, a spec sheet, or the measured constant.

The quoted lines are the top of the running example’s file. A model file has eight top-level keys.

KeyWhat it holdsIf you leave it out
dsl
which version of the file format’s rules the file is written against
the file loads, but the build refuses it
model
the model’s identifier; its results are named <model>-<scenario>
the file does not load
titlethe name a reader seesthe model’s identifier
description
prose saying what the model is for, the one thing the graph cannot show
nothing is shown
currency
the currency the model’s answers are in, as a three-letter ISO code
USD
nodesevery quantity in the model, by namethe file does not load
outputswhich nodes are answersthe file loads but the build refuses it
correlationspairs of inputs that move togetherevery uncertain input is independent

Dollars and euros do not add: each currency is a kind of quantity of its own. A model answers in one currency, the one named in currency. When you leave it out, the build uses USD. The toolkit knows a fixed set of codes in CURRENCIES in sizing/units.py. A currency not on that list is refused. An output whose unit is in another currency is refused. A price quoted in another currency can still go in the model. Convert it with an exchange rate: an input of its own, in a unit such as USD/EUR, with a source like any other.

By convention, the identifier is also the name of its folder under models/. Nothing checks that the two match. The nodes follow these keys, under nodes:.

The node kinds

Node kindCountWhat it carries
input37a value or a distribution, a provenance kind and a source
derived51
a formula, whose declared unit is checked against what it produces
measured1
a stamped result, a standard error, and the implementation it belongs to
ceiling6a limit, a declared headroom, and a reason
classified as a conditional model — it has measured constants or ceilings in it, so sampling the inputs is not sufficient on its own

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

The table counts each kind of node in the running example’s finished model, which Appendix E shows in full. Its last row classifies that model. The file decides whether a model is conditional or definitional, not its author’s opinion. A model containing a measured node or a ceiling node is a conditional model: it has an empirical constant at one stack and version, or a limit past which its arithmetic stops describing anything. In either case sampling the inputs is not sufficient on its own; a model with neither is definitional.

Every node is a mapping under its name, and holds these keys.

KeyKindsIf you leave it out
kindevery nodethe file does not load
unitevery nodethe file does not load
labelevery nodethe name is shown with underscores as spaces
noteevery nodenothing; shown in node details if present
decidedinputthe build refuses it
provenance (kind, source)inputthe build refuses it
valueinputthe median of the distribution
distributioninputone number, not randomised
rangeinputno slider
formuladerivedthe file does not load
shape, start, rate, overgrownthe file does not load
ceilinggrown, levelling shape onlythe file does not load
resultmeasuredthe file does not load
ofceilingthe file does not load
limitceilingthe file does not load
headroomceilingthe build refuses it
becauseceilingthe build refuses it

kind is one of input, derived, grown, measured, or ceiling; unit must be known to the build or the file does not load (use dimensionless for a pure number). Appendix D lists the unit names. An input needs a value, distribution, or both; with neither the file loads but the build fails when evaluating scenarios.

The loader reads these keys and no others. It refuses any other key, anywhere in a model file or scenario file: in a node, at the top, in a provenance, in a correlation or in a scenario. When it refuses a key, it names the nearest key it knows, so lable: is reported with label beside it. If the loader ignored them, two misspellings would change the answer without a word: correlation: would leave every input independent, and override: would run a scenario on the model’s own values.

input — a number the model is given

An input carries a value, a distribution, or both. If you give both, the value is the single number the tables and interactive page use to start, and the distribution is what the sampler draws from. With only a distribution, the single number is its median.

A scenario can pin an input to one number. That number replaces both the input’s value and its distribution in that scenario.

Every input must also have a decided key, saying who settles the number:

The build refuses an input without a decided key or with any other value. An input decided by you is marked with a bar on its left edge in the graph and interactive page; that is the legend’s “you decide”. Every input also has a provenance kind and a source the build will not let you leave empty. The input quoted below, annual growth, is outside: it has a distribution, and nobody in the model chose it.

  annual_growth:
    kind: input
    decided: outside
    unit: dimensionless
    label: annual growth factor
    distribution: {lognormal: {p10: 1.12, p90: 1.60}}
    provenance:
      kind: assumption
      source: >-
        ch04 — lognormal because growth compounds and the factor cannot be zero or less.
        One future in ten grows by less than 12% a year, and one in ten by more than 60%;
        outside that range you would be surprised. One factor for requests and for
        records, because users drive both. It is a share a year, not an amount, which is
        the model's assumption about how this service grows.
    range: [1.0, 2.0]

range is what the interactive page turns into a slider. It is a plausible span for a reader to explore, not a claim about the distribution — the distribution is the claim about the distribution.

derived — arithmetic

A formula over other nodes, and a unit that has to agree with what the formula produces:

  horizon_periods:
    kind: derived
    unit: dimensionless
    formula: horizon / one_year

The formula language is deliberately not Python. It is parsed with Python’s own parser and then walked, and only these functions survive the walk:

FUNCTIONS: dict[str, Any] = {
    "min": min,
    "max": max,
    "ceil": math.ceil,
    "floor": math.floor,
    "sqrt": math.sqrt,
    "log": math.log,
    "exp": math.exp,
}

Arithmetic is + - * / ** and unary minus. There is no name lookup other than other nodes, no attribute access, no calls to anything not in that dictionary. A model file cannot do anything, so running a stranger’s model is reading their arithmetic rather than executing their code.

grown — a quantity grown over periods, in a declared shape

A grown node grows a starting value over a count of periods, in a shape it names. The reader picks the shape by name rather than writing the formula. It has four keys: start, rate, over, each the name of another node, and shape; the levelling shape adds a fifth.

Two shapes govern how the rate applies. compound is where the rate is a factor applied once per period; linear is where the rate is an amount added once per period. Each shape needs its own kind of rate, and the build holds it to that. A compounding rate must be a factor with no unit. A linear rate must be in the starting value’s unit. over must be a count with no unit: divide the horizon by one period in a node of its own, as the running example’s horizon_periods does.

A third shape, levelling, grows like compound while the quantity is far below its ceiling, then slows as it nears it, never passing it. Its rate is a factor with no unit: the growth while far from the ceiling. A levelling node needs a fifth key, ceiling, naming a node in the starting value’s unit; any other shape refuses a ceiling.

Below is the loader’s list of shapes and their formulas, where a name in braces stands for the value of the key of that name: start (starting demand), rate (the growth factor, or for linear the amount added each period), over (the count of periods), ceiling (maximum for levelling only). The notation ** means raised to the power of:

GROWTH_SHAPES = {
    "compound": "{start} * {rate} ** {over}",
    "linear": "{start} + {rate} * {over}",
    # The logistic curve: compounds at `rate` while demand is far below `ceiling`, and flattens as
    # it nears it. Written in the factor, so the same rate means the same early growth as compound.
    "levelling": "{ceiling} / (1 + ({ceiling} / {start} - 1) * {rate} ** -{over})",
}

A rate of the wrong kind is refused with a message naming the shape and the kind of rate it needs, and pointing to the other shape. start, rate and over take a node’s name, not arithmetic: work a value out in a node of its own and name that.

A grown node exists because the shape is a choice about the model’s structure, and the model’s futures vary the inputs, never the structure. Written as a word in the file, the shape is where a reviewer reads it and can argue with it.

In every other respect a grown node is a derived node: the build fills in the shape’s formula, checks its unit, and the interactive page and the graph show it as derived.

Here all three shapes grow from one starting rate:

  compounded:
    kind: grown
    unit: request/second
    shape: compound
    start: start_rate
    rate: factor
    over: periods
  added:
    kind: grown
    unit: request/second
    shape: linear
    start: start_rate
    rate: rise
    over: periods
  levelled:
    kind: grown
    unit: request/second
    shape: levelling
    start: start_rate
    rate: factor
    over: periods
    ceiling: market_ceiling

This model is a case in the conformance suite, which holds any other implementation of these rules to the same answers and the same refusals.

measured — a constant somebody measured

Not a value. A reference to a stamped result:

  record_compression:
    kind: measured
    unit: dimensionless
    label: record compression ratio
    result: records-compression

The number, its standard error and the implementation it belongs to all come from bench/results/. That is what separates a measured constant from an input that happens to have been measured once. If the result does not exist, the node has no value and neither does anything downstream of it — the state propagates by itself and the figures say not yet measured rather than showing an estimate (ch03).

Your own measurements

Measured nodes reference results stored by the book in bench/results/. A model can also reference results from a results/ folder beside the model file, alongside the scenarios/ folder. The build looks there first. If the file is not found, it falls back to the book’s folder. This is where measurements specific to your system go: spans per request on your application, or how well your data compresses.

Without the folder, you have two poor choices. Name a result that does not exist, and the chain stays not yet measured. Or declare the number as an input with provenance fact. Then it loses its standard error, the implementation it was measured on, and its mark as measured. If it was the model’s only conditional element, the model turns definitional.

A result file in your folder with the same name as one of the book’s replaces it. Your compression ratio overrides the one the book measured on its corpus.

The file is the node’s result plus .json. A node with result: records-compression reads results/records-compression.json. The name must be a plain file name. A name with a folder in it, such as ../x, finds nothing, and the node stays not yet measured.

A result file in your folder is held to the rules for an estate result. Nobody else can take your measurement again, and the build cannot re-derive it. The build checks what it can: the value, a standard error above nought, a unit that matches the node, and a named implementation. Whether the measurement was taken as the file says is for a reader of its disclosure to judge.

The file must record:

The model viewer marks the node as your own measurement and shows the system, window and date beside it.

ceiling — where the arithmetic stops working

A quantity, a limit, a margin, and a reason:

  queueing_headroom:
    kind: ceiling
    unit: dimensionless
    label: utilisation at the busy hour
    of: utilisation
    limit: 1
    headroom: queueing_margin
    because: >-
      Not a capacity limit: a fleet that is busy most of the time, but short of fully busy, has not
      run out of anything; it has a queue in front of it. The margin is large because crossing it is
      paid for in waiting time by every request, not in a failure that pages the people on call
      (ch06).

of is the quantity the ceiling watches, and its value is what of works out to (checked like a formula). limit is where arithmetic stops; it must match the ceiling’s unit. headroom is the margin below the limit as a fraction of it; it must be a plain number. In the quoted ceiling, of is fleet utilisation at busy hour, limit is full utilisation, and headroom is queueing_margin. A plain-number limit works only for a dimensionless ceiling, and every ceiling in the book is one. The build refuses a plain-number limit in any other unit, TB included. A ceiling in any other unit takes its limit from a node.

The ceiling allows the limit less the headroom’s share of it:

        allowed = limit * (1.0 - headroom)

The headroom is a share, not an amount subtracted; the larger it is, the smaller the allowed portion of the limit.

Each ceiling gets one of three verdicts:

When the inputs are drawn at random, the report shows the share of futures above the allowed level and above the limit. ch11 argues that a design inside its headroom has not failed; it has spent the reserve it kept for one.

of, limit, and headroom are all expressions rather than numbers, so a sizing formula’s margin and a ceiling’s margin can be the same node. Writing the same figure in both places is how a design gets sized for one headroom and checked against another, some months after anybody remembers there were two. because and headroom are both required. A ceiling with a limit and no margin is not a sizing rule but a comparison, and the build refuses it; an empty because counts as none.

Provenance

#: How much a modeller is claiming when they write a number down.
#:
#: Three, and the gap between the first two is the one that costs money. A ``fact`` is something
#: this repository can point at: a stamped measurement, an invoice, a published specification. A
#: ``vendor_claim`` is a number somebody selling you something has stated — often true, never
#: checked here, and coloured differently in every figure so that it cannot quietly become the
#: first kind. An ``assumption`` is a decision, and naming it as one is what lets a reviewer
#: argue with it.
PROVENANCE_KINDS = ("fact", "vendor_claim", "assumption")

Every input has a provenance mapping with two keys: kind, one of the three shown above, and source, text saying where the number came from. The build refuses an input with an invalid kind or an empty source. For a sampled input, the source must also name its own distribution shape, as a word: triangular, lognormal, uniform or normal. Naming a different shape does not count: a triangular input whose source mentions “a normal week” is refused. A word containing the name does not count either: “lognormal” does not name normal.

A fact has to cite something. The build counts a source as citing when it contains one of these strings:

#: A `fact` has to point at something. Any of these in the source string counts as pointing.
CITATION_MARKERS = ("bench/results/", ".json", ".yaml", "definition", "invoice", "@", "http")

The check only looks for the string, so a source can pass and still point at nothing; a reviewer reading the source does the rest of the check. A fact whose source is “the vendor’s datasheet” is refused because it names a document but contains none of these strings. As a vendor_claim, the same source passes, provided the input is not sampled or the source also names its shape.

Distributions

An input’s distribution names exactly one shape, and under it the keys that shape takes. The quoted input uses this pattern: a lognormal with its two keys. The table lists the four shapes and their keys, read from the sampler’s own code so it cannot drift from what a file may write:

ShapeKeys under it
uniformminimum, maximum
triangularminimum, likely, maximum
lognormalp10, p90
normalmean, sd

Source — sizing/mc.py: each shape in SHAPES, and its function’s parameters

A distribution naming no shape, two shapes, or keys its shape does not take cannot be worked out; the build fails when evaluating scenarios. The same applies to values out of order: a uniform whose minimum is above its maximum, a likely outside minimum and maximum, a p10 of nought or less, or a p10 above the p90. A fifth shape needs a percentile function and a line in SHAPES in two files: sizing/mc.py and sizing/viewer/sample.js. The latter is the copy the published pages sample with. A test holds the two tables to each other for every shape a model uses.

Appendix C is one page each on what they assume and how they lie.

Outputs

Which nodes are answers. Everything else in the graph is working:

outputs:
  # The sizing and the price, first: what a reader of ch12 and ch18 wants.
  - hosts_recommended
  - hosts
  - tco
  - cost_per_million_requests
  - cost_per_stored_tb_month
  - capex
  - annual_opex
  - annual_energy
  # The ceilings, and what each one is about.
  - queueing_headroom
  - failure_headroom
  - cache_fill
  - disk_fill
  - scaling_loss
  - coordination_headroom
  # Part II's own figures. Terminal in the finished model, and outputs because a quantity the
  # book quotes has to be one -- a node that feeds nothing and is reported nowhere is a leftover.
  - utilisation
  - residence_time
  - waiting_time
  - concurrency
  - in_flight_unqueued
  - optimism
  - headroom_to_peak

The list decides what the tables report and what the tornado is drawn against. It is not a restriction — every node keeps its value and its distribution, and the interactive page will show you any of them. It is an editorial judgement about which handful of numbers you are going to be asked about.

Correlations

A model may declare that two quantities move together. Each entry has four keys: a and b, the two nodes; rho, how strongly they move together; and because, the reason:

correlations:
  - a: peak_request_rate_t0
    b: service_demand
    rho: 0.4
    because: >-
      The unhappy one. A busier service is usually a slower one per request — caches miss more,
      locks are held longer, the garbage collector runs while somebody is waiting. Treating the
      two as independent understates the tail of every figure in this model, and it understates
      it exactly when the fleet is busiest.

  - a: host_price
    b: network_price_per_host
    rho: 0.5
    because: >-
      Both are quoted by the same supply chain in the same quarter. A year when hosts are scarce
      is usually a year when optics are, and treating them as independent narrows the interval
      on capital cost by pretending one can save you from the other.

rho is a rank correlation, between −1 and 1; ch14 explains why ranks rather than values. The build refuses a rho that is not a number or is outside that range. Pairs that cannot all hold at once stop the model from being worked out.

a and b must each name an input with a distribution or a measured constant. The build refuses a pair naming anything else: a misspelt name, a derived node, an input with no distribution. One case is still dropped without a message: an input that a scenario pins to one number. In that scenario the pair is ignored, because a number that does not vary cannot move with anything. The build refuses a correlation whose because is missing or empty: it is part of the rule that every input says where it came from. A coefficient with no reason attached is a number the next modeller copies without knowing what it was for.

Scenarios

A scenario is a small file in the scenarios/ folder beside the model file. The build evaluates every file in that folder. A scenario sets some of the model’s numbers, says why, and fixes how many futures are drawn and the seed so the run can be repeated exactly. The one quoted here buys the fleet the high-growth case needs:

scenario: sized_for_growth
title: Sized for the growth we might get, not the growth we expect
because: >-
  The reference scenario buys what the point estimates recommend, and the model then puts a good
  share of its futures past the limit on utilisation at the busy hour and past the working set's
  margin. This scenario buys the fleet the model recommends when annual growth is at the high end
  of its band—one future in ten grows faster—with every other input at its point estimate. The two
  scenarios sit side by side so the trade-off is visible in numbers. Five of the six ceilings
  fall. One rises into its margin: the share of the fleet doing nothing useful, because each added
  host brings less capacity than the last (ch07). The decision between them is a judgement that
  the person who signs for the fleet makes and defends (ch21).
samples: 100000
seed: 20260916
overrides:
  hosts: 131
KeyWhat it holdsIf you leave it out
scenariothe scenario’s namethe file does not load
titlethe name a reader seesthe scenario’s name
becausewhy this scenario existsnothing
overridesnodes and their values in each node’s unitthe model runs on its original values
sampleshow many futures to drawthe loader uses a default, which the result records
seedwhere the random draws startthe loader uses a default, which the result records

An override may name an input or a measured constant. An overridden input is not drawn at random in that scenario; it is pinned to the one number, and any correlation naming it is dropped. The build refuses an override naming a non-existent node or a derived node, which would amount to editing the arithmetic while claiming to change an assumption. An override on a ceiling is accepted but changes nothing; a ceiling’s value is always what its of works out to. To move a ceiling, override the inputs that its of, limit, or headroom read.

ch21 reads this scenario beside the reference one to show what the extra hosts buy; ch22 compares two designs each described by a scenario file without editing either into the other.

What the build checks

A model meets two checks. The loader reads the file into a graph and stops at the first thing it cannot read. Then scripts/verify-models.py runs on every model on every push, reporting every problem it finds at once rather than stopping at the first (CI runs it: scripts/ci-check.sh).

When the file loads

The loader refuses these:

When the verifier runs

The build refuses these:

What nothing checks

The build accepts all of these without a word:

The graph

The graph shows the running example as ch02 leaves it: inputs and derived nodes, and nothing else. It has no ceiling and no measured constant, so it is a definitional model; ch06 is where it stops being one. Reading right to left from any answer gives exactly the quantities it rests on, and reading left to right shows how few inputs most of the graph is downstream of. Both of the book’s finished models have all four kinds in them: Appendix E, the running example, and Appendix F, the second model.

Running it

python3 -m bench.run_models                  # evaluate, sample and stamp every model
python3 -m bench.run_models --model NAME     # just one
python3 scripts/verify-models.py             # units, provenance, ceilings, classification
python3 scripts/build-viewers.py             # the interactive pages
By Chris Snow, in collaboration with Claude (Anthropic) · Prose and figures: CC BY-NC 4.0 · Code and models: Apache 2.0