Eloverblik

Dokumentation · Arkitektur og beslutninger

ADR-004 – The product at 500 metering points: the query that breaks first

Status: measured; the remedy is the lead's to decide (section 9). Written by worker elo-b73-scale-measurement (Claude · Opus) on 23 November 2026 for B73 (docs/architecture/phase-2.md §6.4, row B73 of §7.2), on the branch build/b73-scale.

Scope of the verdict: the queries that exist on 23 November 2026 (commits 3f12c2c, 8a5ed97, and 5b42ee5 after B54): those of phase 1, B20's heat map (consumption.weekday_hours) and B54's selection and measures. The runs at 50, 80 and 150 roots and the first at 420 were made before B54 reached main, so there "one price area" is the list of that area's roots; section 4.1a measures sel itself at 420. Prices, cost and the grid's mix do not exist yet (B52, B53, B56–B59) and nothing of them is measured. The lead runs the one command again after B59 (section 8): the tool measures every query of the catalogue that takes a selection, so a query added by then is measured without a change to it.

1. The answer

**overview.cards breaks first, between 80 and 150 roots, by the API's timeout and inside the row budget: at about 81 roots by its own growth.** It is the overview's first query (X1, its default view: ytd, all roots, cmp=py). At 80 roots it answers in 29.84 s (the slowest of five 29.91 s) with 1 674 336 reading rows, where the budget allows 2 000 000; the API's statement timeout is 30 s. Its seconds grow by 0.37 s a root between 50 and 80 roots, so it passes 30 s at about 81; the budget would refuse it only from 92. At 150 and 420 roots it answers too_large_for_grain.

The others break later, in this order:

Query (default view)Breaks atBySeconds before it breaks
overview.cards~81 rootsthe 30 s timeout29.84 s at 80 roots, 1.67 M rows
overview.months G01, development.series G01, overview.mp_variance92 rootsthe row budget (ytd with py: 2 000 000 rows at 92 roots)21.1, 21.0, 19.5 s at 80 roots
consumption.weekday_hours, report.footprint184 rootsthe row budget (ytd, no comparison)4.7 and 17.6 s at 150 roots
overview.months and development.series E01, E03, ENET (B54), meta.context, the queries of one point (D1)not at 420–E01 0.59–0.65 s, E03 0.19–0.21 s, ENET 1.06–1.09 s, meta.context 0.11 s, D1 at most 0.49 s at 420 roots

The budget's crossings are computed from the organisation and agree with the rows the tool counted at every size (1 064 064, 1 674 336 and 3 333 024 for ytd with py at 50, 80 and 150 roots). The row budget of P1 §10.3 does what it was built for from 92 roots on: every figure made from readings answers too_large_for_grain in 0.02–0.18 s instead of running for a minute. **Below 92 roots it does not protect the overview**: the cards query is refused by nothing and runs into the timeout first.

The prediction of §6.4 holds: at 420 roots a year at hour level is 9 388 800 rows with its previous year (4 694 400 without), the budget admits 138 days of all roots without a comparison and 69 with one ("about four and a half months, about two"). E01 by day or month reads ts.day_load and holds: 0.59 s (overview.months) and 0.65 s (development.series) for the year with its previous year at 420 roots, 2.8 s for the six years.

summary of the tool, which knows only the measured sizes, says "breaks first: overview.cards, overview.months G01, overview.mp_variance, development.series G01 at 150; consumption.weekday_hours, report.footprint at 420". The 81 and 92 of the table come from the 80-root run and the computed crossings.

2. The organisation and the load

AspectValue
The organisationelo_devtools.synth.bulk: 420 roots in 20 blocks of 21 (18 hourly roots, one of them with the owner's tree D15 and D07 hourly, D06 quarter-hourly; three quarter-hourly roots, one with a D06), so that the first n roots hold the mix in proportion; two roots in three in DK1, one in DK2. 500 metering points, 400 hourly and 100 quarter-hourly series, 2021-01-01 to 2026-12-31 (2 191 days): 42 067 200 readings, all A04
FactorsThe generator's (synth.factors), 2021–2026, DK1 and DK2, the three allocations: 315 504 rows, generated
Not generatedPrices and the mix (B52, B53 do not exist yet); no missing, estimated or corrected interval (the bulk path writes complete days; the cases are the demo organisation's)
The loadAs elo_owner, in the Compose project elo-b73 and its own volume: the database makes each series' readings (generate_series) and writes every day's summary and hash in the same statement, by the expressions of ts.day_facts
Load rate66 303 readings/s (50 roots, 4.9 M readings, 75 s); 76 107 (to 80, 2.6 M, 34 s); 69 913 (to 150, 7.7 M, 110 s); 64 034 (to 420, 26.9 M, 420 s)
make verifyPasses on every stored day: at 50 roots 133 651 series-days, no difference, 95 s; at 420 roots 1 095 500 series-days, no difference, 11 min. The sample check (bulk --verify-sample, ts.verify's comparison over chosen series of every kind) passes: 12 series and 26 292 days at 50 roots, 25 series and 54 775 days at 420
The diskThe tool estimates a load from the rows it is about to write (104–105 B a reading with its day row, measured once a million are stored, 140 B assumed before) plus 1 GiB of WAL, and refuses one that would leave under 10 GiB free on the VM. The estimates the lead approved: 150 roots +2.0 GiB, 420 roots +4.6 GiB (19.5 GiB left of 24.1)

3. How it was measured, and what was cut

One command, python -m elo_devtools.scale (section 8). Seconds are measured through HTTP as elo_api (Caddy, the stack's own API), warm: a first request and then the measured ones. The rows each cell would read are counted as the budget counts them (providers/budget.sql).

The lead's ruling of 23 November 07:33 cut the matrix of §6.4 after the first numbers showed that a run of the whole matrix takes three to four hours a size ("the question is which query breaks first and at how many roots, not every cell"):

  1. the verdict's cell of every query (its page's default view: ytd, all roots, py; a query of one point: its one root and 30d, the longest window its hours hold): five warm repeats, the median and the slowest, at 50, 150 and 420 roots, the budget on; 2. every other cell once, warm: periods 30d, 12m and the six years; all roots and one root at every size, the list of 100 roots and one price area at 420 only; cmp=py, and cmp=none for the default view only; 3. the budget off: the default view and 12m with all roots only, under a statement timeout of 60 s, "over 60 s" when it is; 4. the repeat run for "within a tenth": the default views at 50 roots; 5. a size stops starting cells after 45 minutes and names those it did not reach (none was cut: the cells took 13.5 min at 50 roots, 22.6 at 150 and 24.6 at 420).

Cut, therefore: five repeats for any cell but the default view; the list of 100 roots and one price area below 420 roots; cmp=none except for the default view; the budget off except for two periods of all roots. The tool keeps the full matrix as --matrix full. Added by this worker: the default views at 80 roots (the load of 30 roots and one run of --matrix defaults), because 50 and 150 left the first break between them.

The machine was shared. The Colima VM (4 CPUs, 6 GiB) ran, beside elo-b73 and its test database, the owner's stack (elo) and the stack elo-b16b throughout, and by turns the test databases of B51 and B66 (50 and 80 roots) and B66's stack (150 roots); each run records its containers. The VM's load average (1, 5, 15 minutes) was 2.3–2.9 around the runs at 50 and 80 roots, 3.2 falling to 1.3 at 150, and 1.4–1.7 at 420. The seconds are not the verdict's precision: the lead should repeat the default views at 50 and 80 roots on a quiet machine (section 8). too_large_for_grain and the row counts do not depend on the neighbours; nor do the plans of section 5.

4. The numbers

Seconds are the median of five (the default views) or one request after a first (the rest). The full tables, with every cell, are written by the tool under docs/adr/ADR-004/, one page per run.

4.1 The default views (the budget on)

Query50 roots80 roots150 roots420 roots
meta.context0.030.040.050.11
overview.cards18.6629.84too large 0.04too large 0.14
overview.months E010.080.120.220.59
overview.months G0113.3721.11too large 0.05too large 0.16
overview.mp_variance6.2019.49too large 0.04too large 0.16
development.series E010.100.150.240.65
development.series G0112.7220.99too large 0.04too large 0.15
consumption.weekday_hours1.452.414.69too large 0.04
report.footprint4.657.6917.55too large 0.04
mp.master, mp.tree, mp.changes, mp.ingestion≤ 0.01≤ 0.01≤ 0.01≤ 0.01
mp.series (30d)0.050.050.080.15
mp.emission_intervals (30d)0.330.350.360.49
Rows the budget counts (ytd, py)1 064 0641 674 3363 333 0249 388 800

"too large" is too_large_for_grain. The slowest of five was within 2 % of the median in every slow cell except development.series G01 at 80 roots (22.03 against 20.99).

4.1a After B54: the selection by a dimension, E03 and ENET (420 roots)

main gained B54 at 09:27 (sel, the measures E03 and ENET, migrations 0195–0196); the branch merged it, the database was migrated, and the default views and one cell by a dimension (sel: {"area": ["DK1"]}, ytd, py) per query that takes sel were measured once more at 420 roots (commit 5b42ee5, --matrix defaults, 40 s):

QueryDefault viewOne price area by sel (280 roots)
overview.cards, overview.months G01, overview.mp_variance, development.series G01too large 0.15–0.16too large 0.10–0.35 (6 259 200 rows)
consumption.weekday_hourstoo large 0.04too large 0.31 (3 129 600 rows)
overview.months E01 / E03 / ENET0.59 / 0.19 / 1.060.46 / 0.19 / 0.88
development.series E01 / E03 / ENET0.65 / 0.21 / 1.090.48 / 0.21 / 0.93

E03 and ENET read ts.day_load (B54) and hold like E01; ENET, which nets the export children against the roots, takes about twice E01. Resolving sel adds nothing measurable to a refusal. The other numbers of this ADR were measured before B54; nothing in B54 changes the hour-level functions of section 5.

4.2 The budget off (statement timeout 60 s)

Query, all roots, py50 roots ytd / 12m150 roots ytd / 12m420 roots ytd / 12m
overview.cards18.45 / 20.66over 60 s / over 60 stoo large 0.14
overview.months G0112.74 / 14.0346.76 / 52.05too large 0.16
overview.mp_variance9.80 / 10.9950.92 / 56.71too large 0.16
development.series G0112.46 / 14.1846.50 / 52.21too large 0.15
consumption.weekday_hours1.44 / 1.614.38 / 4.91too large 0.04
report.footprint4.70 / 5.0917.65 / 19.70too large 0.04

What the budget protects against: at 150 roots the four G01 queries of the overview and of A1 run 47–57 s each, and the cards query passes a minute; with the budget on they answer in 0.05 s.

A defect the measurement found. With the budget off at 150 roots overview.cards answered HTTP 500 after 60.04 s, not the API's 503 query_timeout. The role elo_api carries transaction_timeout = 60s beside statement_timeout = 30s (elo_api.db.bootstrap); the measurement raised the statement timeout to 60 s, so the transaction timeout fired at the same instant, PostgreSQL ended the connection (TransactionTimeoutError), and the route treats a closed connection as a failure, not a timeout. With the role's own settings the statement timeout fires 30 s first and the answer is 503, so the product is not affected today; but a query whose transaction holds several statements adding up to 60 s would get a 500. The route maps 25P04 (the transaction timeout's SQLSTATE) already, but PostgreSQL ends the session with a FATAL error, and asyncpg raises ConnectionDoesNotExistError and then an InterfaceError at the transaction's exit: neither is a PostgresError with that state, so the route's last branch answers 500. For the lead, in the lane of the named queries: treat a connection closed by transaction_timeout as a timeout. The tool now raises the transaction timeout beside its own statement timeout and counts a 5xx at the timeout as a timeout, "over 60 s (HTTP 500)".

4.3 Other cells

Cell (the budget on)50 roots150 roots420 roots
overview.cards 30d, all roots, py1.876.0011.94 (865 200 rows)
overview.cards ytd, all roots, cmp=none4.1117.33too large (4 694 400 rows)
overview.cards one root, ytd / six years0.93 / 4.561.24 / 5.992.32 / 12.95
overview.cards 30d, list of 100 / one price area (280 roots)––3.23 / 8.46
overview.months G01 30d, all roots1.364.498.17
overview.mp_variance 30d, all roots / one price area0.59 / –4.61 / –4.92 / 14.03
consumption.weekday_hours one root, six years0.400.601.33
report.footprint one root, six years1.852.303.88
E01 (overview.months, development.series), all roots, six years0.25 / 0.251.00 / 1.012.80 / 2.82
Any query answering too_large_for_grain0.02–0.030.04–0.050.04–0.18

At 420 roots the whole six years, the year and ytd of all roots are refused for every figure made from readings; 30 days of all roots answer in 1.3–11.9 s. A list of 100 roots answers 30 days and is refused for ytd (2 128 128 rows with py). Even a refusal costs more as the database grows (0.02 s at 50 roots, up to 0.18 s at 420): the frontier and the budget's estimate read ts.day_load.

4.4 The daily run, make status, sizes

RootsThe daily run (14 days)make status
50854 ts.apply_day calls, all confirmed: 854 updates of ts.day_load, no reading touched, no change row; 2.0 s1.25 s (0.37 s the container's start), 223 lines
1502 534 calls, 2 534 updates; 2.5 s1.58 s, 583 lines
4207 000 calls, 7 000 updates; 4.1 s2.61 s (0.33 s), 1 540 lines

The daily run is ts.apply_day over the 14 days ending at the frontier for every series with its stored points, as the worker's role, in one transaction that is rolled back: the database's half of a run in which every day is confirmed (P1 §1.4: "one ts.day_load update per series-day in the 14-day window"); the calls to Eloverblik, its pacing and the merge's Python are not in it. make status is the worker's status program in a one-off container of its image (the stack runs no worker), so its seconds include the container's start.

Relation50 roots150 roots420 roots
ts.reading (the table)321 MiB981 MiB2 713 MiB
ts.reading_pkey150 MiB459 MiB1 267 MiB
ts.day_load and its key19 + 3 MiB57 + 9 MiB157 + 24 MiB
fx.factor_hour38 MiB38 MiB38 MiB
All relations0.53 GiB1.52 GiB4.11 GiB

A reading costs 64.6 B in the table and 31.6 B in its key; with its share of the day rows, 101 B. The daily run's updates grow with the series (14 a series), not with the history: 7 000 a day at 500 series, as P1 §1.4 said.

5. Where the time goes

The parts of overview.cards at 80 roots, ytd with py, run one by one in psql as elo_api:

FunctionSecondsReads
calc.emission_buckets by month, with the comparison21.3every reading of the period and its previous year, joined to the factor of its hour and price area, and the like-for-like hour cells (P1 §9.3)
the same without the comparison7.1the period's readings and factors only
calc.consumption_matched9.0every reading of both years, hour cell by hour cell (B15b's like-for-like consumption)
calc.consumption_buckets by month, and by point0.12, 0.11ts.day_load only

The cards query is the sum of the two hour-level functions (21.3 + 9.0 ≈ 30 s); the day summaries cost nothing. That is why E01 holds at every size and every G01 figure does not, and why cmp=none is a third of py (4.1 s against 18.7 at 50 roots): the comparison doubles the rows and adds the matching of hour cells. overview.mp_variance (19.5 s at 80 roots, tripled from 6.2 at 50 while its rows grew by 1.6) is calc.consumption_matched per root and ranked.

The plan of a small selection reads every reading of its period. One root over six years, the same 52 584 rows at every size, took 4.56 s at 50 roots, 5.99 s at 150 and 12.95 s at 420 (overview.cards); the heat map and the report grow alike. auto_explain (nested statements, ANALYZE) on calc.emission_buckets and calc.consumption_matched for that root at 420 roots shows why: 288 sequential scans of the monthly partitions of ts.reading (72 months, both sides, both functions), each returning every row of its month (594 400 rows for March 2024), joined to the selection's series by Hash Cond: (r.series_id = s.series_id). The functions plan with nested loops disabled (B15f: before ANALYZE the planner chose a nested loop that took every emission query past 30 s), and without a nested loop the key (series_id, interval_start) cannot be used for a join. The cost of a one-root figure is therefore the size of the database in the period, not the size of the selection; at 500 points it is still inside the timeout, at 5 000 it would not be. What holds it: give the reading scan the selection's series as a condition of its own (r.series_id = ANY (<the series, computed first>)), which every partition answers from its key whatever the statistics say, and keep nested loops off for the join to the factors. This is a plan, not a stored fact, and it is independent of the neighbours.

6. What would hold each broken query

QueryA higher budgetA stored fact, and its grainA different grain of the page
overview.cardsNo: it breaks inside the budget. A lower budget (about 1.6 M rows) would turn the timeout into too_large_for_grain at 80 roots, which is a refusal, not an answerDay facts per root, local day, method and data basis (S §2.7): energy, emission and provisional emission, hours with a quantity, with a factor, pending; and a stored matched measure per root and day (the like-for-like cells counted and summed against the previous year's day, P1 §1.4). The cards are period totals and monthly strips: a day grain reads 420 × 365 × 2 = 306 600 rows for a year with its previous year at 420 roots, against 9.4 M readingsE01's card already reads ts.day_load (0.1 s at every size); a like-for-like rule defined by the day (P1 §1.4 "or a day-level definition") would remove calc.consumption_matched's hour join, and leave the emission's
overview.months G01, development.series G01No beyond ~110 roots: with the budget off they took 47–52 s at 150The same day facts of emissions: a month or day bucket is a sum of day factsA coarser grain does not help: the cost is the hour join, whatever the bucket
overview.mp_varianceNo: 51–57 s at 150 with the budget offThe stored matched measure per root and day–
consumption.weekday_hoursYes, to 420 roots: with the budget off 12.95 s for ytd (4.69 M rows) and 14.51 s for 12m (5.26 M) at 420; a budget of 6 M rows holds it, inside the 30 s, to 420 rootsNot needed if the budget rises; else a fact per root, weekday and hour of the day per month–
report.footprintYes, to 420 roots, narrowly: 23.5 s for ytd and 26.3 s for 12m at 420 with the budget off (and 17.7 s at 150: the seconds grow less than the rows)The day facts of emissionsIt is the validation's, not a page's: a longer timeout for it alone is a choice

7. Repeatability

The default views at 50 roots, a second run of the same command an hour after the first (--matrix defaults): the 15 default views took 57.66 s and 55.06 s, a difference of −4.5 %; every view of 0.1 s or more is within a tenth of the first run (the largest difference −7.9 %, overview.months G01). Three views of 4–7 ms differ by 13–28 %, which is one or two milliseconds. By the lead's ruling the repeat is the default views at 50 roots; the lead's own run after B59, on the database of 420 roots, is the second repeat (compare reads two runs' files).

8. For the lead: repeating it, and removing it

The database of 420 roots stays in the Compose project elo-b73, its containers stopped (start them with the first command below) (volume elo-b73_pgdata): the database is 4.13 GiB, the volume 5.5 GB (5.1 GiB) with its write-ahead log; the VM had 19.8 GiB free after the load and the runs.

# the stack (no worker; Caddy on 18104): from this worktree
export DOCKER_CONTEXT=colima-elo COMPOSE_PROJECT_NAME=elo-b73 ELO_PORT=18104 \
    ELO_UID=$(id -u) ELO_GID=$(id -g) ELO_STATE_DIR=$PWD/data/b73-state \
    ELO_WEB_DIR=$PWD/data/b73-web ELOVERBLIK_REFRESH_TOKEN= ELO_DEMO=1
docker compose --env-file deploy/dev.env -f deploy/compose.yaml up -d postgres migrate api caddy
# the measurement (the lead's matrix; --matrix defaults for the default views alone)
uv run --locked --all-packages python -m elo_devtools.scale
# the verdict over several runs
uv run --locked --all-packages python -m elo_devtools.scale summary data/scale/*-roots.json

To repeat on a quiet machine: the default views at 50 and 80 roots (the bulk loader writes the first n roots of the same organisation into an empty project: python -m elo_devtools.synth.bulk --roots 80).

Removing it, the one command (the project's containers and its volume, nothing else):

DOCKER_CONTEXT=colima-elo docker compose -p elo-b73 down -v --remove-orphans

9. Decision

The lead decides the remedy. What this worker would put to the lead, in order:

  1. Find the readings by the selection's series (section 5): a one-root query reads every reading of its period today. It is a change to the reading functions' text, with no stored fact, and it removes the growth of a small selection's seconds with the size of the database. 2. Stored day facts of emissions and a stored matched measure per root and day (S §2.7, P1 §1.4), the candidates of §6.5: they hold the overview's cards and the G01 figures beyond 92 roots; nothing else measured here does. 3. The row budget, until then: a budget near 1.6 M rows turns the cards' timeout between 80 and 92 roots into a refusal; a separate, higher budget for the heat map and the report (6 M) holds those two to 420 roots. 4. The 500 at the transaction timeout (section 4.2), in the lane of the named queries.

The lead's decision (23 November 2026, 09:36).

  1. Now, as an epic of its own in the lane of the named queries, after B66 and before B55 (B77): the reading functions find their readings by the selection's series (section 5: a plan, no stored fact); the row budget becomes a number per query (the cards' about 1.6 M rows, so that the overview is refused at 80 roots and does not run into the timeout; the heat map's and the report's 6 M, which holds both to 420 roots); the API answers 503, not 500, when the transaction's timeout ends the connection. 2. Stored facts are the remedy for the figures made from readings beyond about 80 roots: day facts of emissions per root, local day, method and data basis, and a stored like-for-like measure (section 6). They are not built from this document: the architect specifies them (phase-2.md §6.5) once B55 (the correspondence of any comparison period), B56 (cost) and B58 (the mix) have merged, so that one design carries emissions, cost, the mix and the like-for-like measure of every kind of comparison, and every stored figure equals what the functions of today compute (they stay, as the reference make verify reads). They are built before a customer's account of more than 80 consumption points is loaded (wave B). 3. Until then the product is said to hold, for one selection: energy figures (bought, sold, net) and the pages of one metering point at 420 consumption points and six years; emission figures, the heat map and the report up to the sizes of section 1, refused above them with too_large_for_grain, never wrong. No sentence about scale goes into the README before the stored facts exist (phase-2.md §6.4). 4. Owed by the lead: the default views at 50 and 80 roots once more on a quiet machine (section 8), with B77 merged; the numbers of this document came from a VM shared with three other workers.

**As built (B77, merged 23 November 2026; docs/build/B77-report.md, docs/queries.md "The budget is a number per query").** Item 1 holds with three numbers changed by the measurement of the build: the cards' budget is 1 500 000 rows (the largest hundred thousand at which the cards stay at nine tenths of the timeout on a busy machine too), so the cards' default view is refused from about 71 roots, and "more than 80 consumption points" in item 2 reads more than 70; the report's budget is 5 300 000 (ytd of 420 roots holds to 31 December; six years of about 59 to 75 roots runs into the timeout and answers 503 query_timeout); the heat map's stays 6 000 000. One root over six years no longer grows with the number of roots (the cards: 2.19 s at 50 roots, 2.16 s at 80). ELO_ROW_BUDGET, when set, replaces every query's own number, upward too: it is for a measurement and is set nowhere in the stack. Item 4 is still owed.

Kilde: docs/adr/ADR-004-scale-at-500.md i løsningens repository.