Appendix A · The DSL, in full
What this holds
| Purpose | Every node kind, every field, every distribution, and what the build checks |
| Source | sizing/dsl.py, sizing/expr.py, sizing/evaluate.py, sizing/mc.py, sizing/units.py, sizing/results.py, scripts/verify-models.py |
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.
| Key | What it holds | If 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 |
title | the name a reader sees | the 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 |
nodes | every quantity in the model, by name | the file does not load |
outputs | which nodes are answers | the file loads but the build refuses it |
correlations | pairs of inputs that move together | every 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 kind | Count | What it carries |
|---|---|---|
input | 37 | a value or a distribution, a provenance kind and a source |
derived | 51 | a formula, whose declared unit is checked against what it produces |
measured | 1 | a stamped result, a standard error, and the implementation it belongs to |
ceiling | 6 | a 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.
| Key | Kinds | If you leave it out |
|---|---|---|
kind | every node | the file does not load |
unit | every node | the file does not load |
label | every node | the name is shown with underscores as spaces |
note | every node | nothing; shown in node details if present |
decided | input | the build refuses it |
provenance (kind, source) | input | the build refuses it |
value | input | the median of the distribution |
distribution | input | one number, not randomised |
range | input | no slider |
formula | derived | the file does not load |
shape, start, rate, over | grown | the file does not load |
ceiling | grown, levelling shape only | the file does not load |
result | measured | the file does not load |
of | ceiling | the file does not load |
limit | ceiling | the file does not load |
headroom | ceiling | the build refuses it |
because | ceiling | the 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:
outside: outside your control, whether or not it has been given a shape yet; the busy hour, the records held, a priceyou: a choice you make and can change; the fleet, the horizon, a headroom margindefinition: an identity nobody chooses and the world does not vary; a year in seconds, one host, one request
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_ceilingThis 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:
target: estateandkind: measurementin
produced_by:system,window,observed_at(the date), andstack(implementation and version)in
summary:valueandsd(its standard error)in
units: a unit for each
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:
ok: at or below the allowed levelinside headroom: above the allowed level but not above the limitover: above the limit
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:
| Shape | Keys under it |
|---|---|
uniform | minimum, maximum |
triangular | minimum, likely, maximum |
lognormal | p10, p90 |
normal | mean, 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
| Key | What it holds | If you leave it out |
|---|---|---|
scenario | the scenario’s name | the file does not load |
title | the name a reader sees | the scenario’s name |
because | why this scenario exists | nothing |
overrides | nodes and their values in each node’s unit | the model runs on its original values |
samples | how many futures to draw | the loader uses a default, which the result records |
seed | where the random draws start | the 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:
A missing key the file needs:
modelornodesat the top;kindoruniton any node;formulaon a derived node,resulton a measured one,oforlimiton a ceiling.A
kindthat is not one of the four, or a unit that is blank or that the build does not know.A formula that is not arithmetic. Anything but numbers, other nodes,
+ - * / **, unary minus and the functions quoted underderivedis refused, so a model file cannot run code.A name that is not a node: a formula that refers to one, or an output that lists one.
A cycle.
A
dslkey naming a version other than the one the toolkit reads.A key written twice in one mapping, such as a node declared twice. Otherwise one copy would be lost without a word.
A key it does not read, anywhere in a model or scenario file. The refusal names the nearest key it knows.
A value that should be a number and is not. YAML reads
yesas true; the loader refuses it rather than treating it as one.minormaxwith fewer than two arguments.A unit that does not convert by multiplying by one factor: a temperature, whose scale has an offset, or decibels, which are logarithmic. Appendix D has the reason.
When the verifier runs
The build refuses these:
A unit that does not follow. Every formula is evaluated in units as well as in numbers. A declared unit that disagrees with what the formula produces is an error. One that agrees dimensionally but differs by a factor, dollars per TB per year against per month, is converted and applied, not waved through (Appendix D). An amount of data is a kind of quantity of its own, not a plain number. So a
TBnode or limit whose formula gives a plain number is refused, and terabytes cannot be an exponent, or sit insidelogorexp.Quantities in different units meeting in a sum, a difference, a
minor amax. The conversion is applied once, to the whole formula’s result, so it cannot fix two operands that were never in one unit.a + bwithainTBandbinTiBis refused. Declare them in one unit, or convert one in a node of its own. A literal0is the exception: it meets any unit.max(0, need - held)is what is left over, or nothing, in the unit ofneed.A
ceilorfloorover a number not yet in the node’s unit. It would round the wrong number, since the conversion comes after.A ceiling whose
limitis a different kind of quantity from itsunit, or whoseheadroomis not a plain number.A file with no
dslkey.A
currencythe toolkit does not know, or an output in a currency other than the model’s.An input with no
decidedkey, or one that is notyou,outsideordefinition.An input with no provenance, a kind that is not one of the three, an empty source, a correlation with no
because, or afactthat cites nothing. Provenance, above, says what counts as citing.
A correlation naming something other than an input with a distribution or a measured constant, or with a
rhooutside −1 to 1.An input that is sampled and does not name its own shape in its source. The distribution is a claim about what can happen, and it is the claim to argue with first (Appendix C).
A measured node that names no result; whose result has no value, or reports no uncertainty; or whose result is in a different unit from the node. Reporting no uncertainty is a claim to have measured something exactly. A result that does not exist yet is not refused: the node is not yet measured, and so is everything downstream of it.
A ceiling with no headroom, or no reason. An empty reason counts as none.
A node that feeds no output, which is either a leftover or an output nobody declared. Also a model that declares no outputs at all, since nothing in it can then be checked.
A measured constant with no ceiling anywhere in the model. A model with empirical inputs and no declared limit is claiming that nothing in it changes regime. That may be true; say it by declaring the ceiling, not by leaving one out.
A scenario that overrides a node the model does not have, or a derived node. Scenarios, above, gives the reason.
A scenario that cannot be worked out. The verifier evaluates the model under every scenario, and this is where problems surface: an input with neither a value nor a distribution, a distribution naming no shape or two, parameters out of order, and correlations that cannot hold.
A stamped model result that no longer matches the model. Every result under
bench/results/from a model run carries a fingerprint of the code and the model file that produced it. Edit either, and the build refuses the old result until you re-runpython3 -m bench.run_models.
What nothing checks
The build accepts all of these without a word:
A correlation whose input a scenario pins. It is dropped in that scenario without a message. Correlations, above, has the details.
A scenario’s
because, and an override on a ceiling, which changes nothing. Scenarios, above, explains both.That
modelmatches the model’s folder name.
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