ADR-R2-17. ETA and autoscaling hooks
Source:
docs/decisions/ADR-R2-17-eta-and-autoscaling-hooks.md. Generated at build time; edit the source file.
Status: accepted (Task 30, spec sections 8d.4 and 8d.5).
Context
Section titled “Context”An account that imports thousands of games waits behind the others. The UI needs an honest “how long”, and the operator needs a signal for adding servers. No cloud API is in R2 scope.
Decision: the ETA (scheduler::eta)
Section titled “Decision: the ETA (scheduler::eta)”Measurements.
total= the account’s games withselected_atset and statuspending,analysingordone.done= thosedone. Failed and skipped games are not counted.games_per_sec=job_metricsrows of kindanalyse-gamein the last 10 minutes, divided by 600. With fewer than 5 rows it isNone.queued_ahead= the 1-based position, in the fair order of ADR-R2-15 (fair_order_sql, no lock), of the account’s last queued analyse job.eta = queued_ahead / games_per_sec, one figure, never a range.
Honesty rules.
- Not enough throughput data:
etaisNoneand the sentence isanalysing {done} / {total}. There is no spinner and no default rate. fair_order_sqlis exact only for its first$2rows (ADR-R2-15). The ETA reads a window of 400 places (ETA_WINDOW). If any queued job of the account is not placed inside it, or is delayed (not due, so not in the order), the last position is unknown andetaisNone.queued_aheadis then a lower bound.- Nothing queued is a known zero (
Some(0), “under 1 min”) only when every selected game is done. Games that are pending or running without a queued job (not scheduled yet, or all in flight) giveNone. - One delayed job (retry back-off) makes the whole ETA
None, even if the last due job has an exact position. This is conservative and can be noisy for accounts with retries. - No NaN or infinity: the rate is a count over a constant, and the duration conversion is checked.
- The sentence is
about {m} min, analysing d / twithm = ceil(eta / 60 s), orunder 1 min, ...below 60 s.
Plan guards. The count and rate reads, and the queue-lag read, have EXPLAIN tests (custom and generic plans, no Seq Scan) on seeded tables. The rate read needed job_metrics_kind_created_idx (Task 3).
Decision: queue lag and autoscaling hooks (scheduler::lag)
Section titled “Decision: queue lag and autoscaling hooks (scheduler::lag)”queue_lag:oldest_p0_ageis the age of the oldest due queued job withpriority / 2 <= 2(analyse and preview), counted from the later ofrun_atandcreated_at; a delayed job does not lag.queued_gamescounts queued analyse jobs.core_seconds_queued= queued games x the meanengine_cpu_msof the last 24 h (12 000 ms when there is no data), divided by 1000.scale_adviceis a pure function and is the hook for an external autoscaler: when P0 lag is overp0_lag_threshold(3 min) it addsmin(max - current, max(1, ceil(core_seconds / (engines_per_server x 600))))servers, as far as the monthly cap pays for whole server-hours. When idle for 15 min or more with extra servers running, it removes one. Otherwise it holds.- Spend needs a positive, finite owner-approved cap AND a positive, finite price, and the projected spend must stay within the cap. A zero, negative, NaN or missing cap or price always means
Hold, so the default config (both 0) never adds a server. A NaN spend also holds. A bad backlog figure asks for one server, not many.engines_per_server == 0is a misconfiguration and holds. - R2 has no cloud API. Whoever runs the autoscaler supplies
idle_for,current_extraand the month’s spend, and applies the advice.