Skip to content

tdfs4ds.sizing

tdfs4ds.sizing

Sizing and scalability of a data domain: what one refresh costs, how storage grows, and a forecast (0.3.8.7).

One refresh of a domain is one step of its clock (what roll_out(data_domain=...) runs). This module answers four questions from what the store already keeps, and changes nothing in it:

  • what does a step cost, in elapsed time, CPU, I/O and peak spool, per process and for the domain, and how does it evolve? (FS_EXECUTION_RESOURCES and the live follow-up <-> DBQL join, one row per execution);
  • how long is a refresh when the processes run one after the other (sequential, what a plain roll_out costs), when the independent ones run together (by_waves, the floor with roll_out(max_workers=) or the generated script) and what really happened (measured, first start to last end in the logs);
  • how many rows (and how many bytes) does each step add? Every stored value carries ValidStart (the business date of the run that wrote it) and FEATURE_VERSION (the process), so one GROUP BY per storage table rebuilds the history of the growth with no new table;
  • where does this lead: the forecast of each series over a horizon, and the date a refresh no longer fits in the time between two steps of the clock.

Three layers, like the other reports:

  • :func:collect_domain_sizing - the only I/O, fail-open, TWO grouped requests (see its docstring);
  • :func:build_domain_sizing - pure: frames -> one JSON-friendly model;
  • :func:render_domain_sizing_html / :func:render_domain_sizing_markdown / :func:domain_sizing_csv.

Public: :func:domain_sizing and :func:write_domain_sizing_report (exported lazily on tdfs4ds). Read only: a source guard (tests/test_domain_sizing.py) keeps every write out of this file.

MIN_STEPS module-attribute

MIN_STEPS = 6

STORAGE_SHAPE module-attribute

STORAGE_SHAPE = 'one pass per table, one statement per table, all in the second request'

HORIZONS module-attribute

HORIZONS = ('month', 'quarter', 'semester', 'year')

SERIES_KEYS module-attribute

SERIES_KEYS = ('sequential', 'by_waves', 'measured', 'cpu', 'io', 'rows_growth', 'bytes_growth')

_DAY module-attribute

_DAY = 86400.0

_METHOD module-attribute

_METHOD = ['Time steps are the business dates of the domain clock (the valid time of each run). The segments of a process in one step are summed; a step recomputed counts once (its latest execution).', 'Sequential = the sum of the run times of the processes of a step (what a plain roll_out costs). By waves = the sum over the waves of the lineage graph of the longest process of each wave: the floor when independent processes run together, assuming each wave runs fully in parallel and the platform has room (processes that write the same storage table must still run one after the other, which this ignores). Measured = first start to last end of the step in the logs.', 'Rows added are the stored rows whose ValidStart is the step (a value that changed, or a new entity). The first step of a process is its initial load and is shown apart: it is not growth. Bytes are an estimate: the rows times the average bytes per row of their table (DBC.TableSizeV CurrentPerm divided by the rows of the table, history included).', 'A forecast is a Theil-Sen line over the step index with a band from the 10th-90th percentile of the residuals. It extends the past: a new process version, a change of data volume or of calendar breaks it. Under 6 usable steps there is no forecast. Steps with a failed or missing process are left out of the fit.', 'Elapsed time depends on the platform (AMPs, concurrent workload, ACC / OFS); CPU and I/O far less. CPU seconds divided by the number of AMPs is a lower bound of the elapsed time of a CPU-bound refresh on another platform, not a prediction.']

CSS module-attribute

CSS = '\n.td-sz{--navy:#00233C;--orange:#FF5F00;--slate:#5A6B7B;--bg:#FFFFFF;--surface:#FFFFFF;--soft:#F5F7FA;--border:#E2E8F0;--teal:#0E7C86;\n--td-navy:#00233C;--td-orange:#FF5F00;--td-slate:#5A6B7B;--td-border:#E2E8F0;--td-surface:#FFFFFF;\nfont-family:"Segoe UI",system-ui,sans-serif;color:var(--navy);background:var(--bg);max-width:1100px;margin:0 auto;padding:20px 16px 40px;line-height:1.45}\n@media (prefers-color-scheme: dark){:root:not([data-theme="light"]) .td-sz{--navy:#E6EDF5;--slate:#9AA9B8;--bg:#0B1622;--surface:#111F2E;--soft:#16273A;--border:#24384E;--teal:#4FC3CE;\n--td-navy:#E6EDF5;--td-slate:#9AA9B8;--td-border:#24384E;--td-surface:#111F2E}}\n:root[data-theme="dark"] .td-sz{--navy:#E6EDF5;--slate:#9AA9B8;--bg:#0B1622;--surface:#111F2E;--soft:#16273A;--border:#24384E;--teal:#4FC3CE;\n--td-navy:#E6EDF5;--td-slate:#9AA9B8;--td-border:#24384E;--td-surface:#111F2E}\nbody{margin:0;background:var(--bg,#fff)}\n@media (prefers-color-scheme: dark){:root:not([data-theme="light"]) body{background:#0B1622}}\n:root[data-theme="dark"] body{background:#0B1622}\n.td-sz h1{margin:0 0 4px;font-size:26px}.td-sz h2{font-size:18px;margin:28px 0 8px;border-left:4px solid var(--orange);padding-left:10px}\n.td-sz h3{font-size:15px;margin:16px 0 6px}\n.td-sz .hero{background:linear-gradient(135deg,#00233C,#0B3A5E);color:#fff;border-radius:12px;padding:22px 24px;margin-bottom:16px}\n.td-sz .hero .kicker{color:#FF9A5C;font-size:12px;letter-spacing:.08em;text-transform:uppercase}\n.td-sz .hero .meta{margin-top:8px;font-size:13px;opacity:.9}.td-sz .hero .meta span{margin-right:16px}\n.td-sz .kpis{display:flex;flex-wrap:wrap;gap:10px;margin:12px 0}\n.td-sz .kpi{flex:1 1 150px;background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:10px 14px}\n.td-sz .kpi b{display:block;font-size:21px}.td-sz .kpi span{font-size:12px;color:var(--slate)}\n.td-sz table{border-collapse:collapse;width:100%;font-size:12.5px;background:var(--surface)}\n.td-sz th{background:var(--soft);text-align:left;padding:6px 8px;border-bottom:2px solid var(--border)}\n.td-sz td{padding:5px 8px;border-bottom:1px solid var(--border);vertical-align:top}\n.td-sz tr:nth-child(even) td{background:var(--soft)}\n.td-sz .num{text-align:right;white-space:nowrap}.td-sz .bad{color:#dc2626;font-weight:600}\n.td-sz .note{color:var(--slate);font-size:12.5px;margin:6px 0}\n.td-sz .card{background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:12px 14px;margin:12px 0}\n.td-sz ul.findings{margin:6px 0;padding-left:20px}.td-sz ul.findings li{margin:4px 0}\n.td-sz li.warning{color:#b45309;font-weight:600}\n.td-sz .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(360px,1fr));gap:10px}\n.td-sz .grid .cell{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--surface)}\n.td-sz .bar{display:block;height:8px;background:var(--orange);border-radius:4px}\n.td-sz .shr{display:flex;align-items:center;justify-content:flex-end;gap:8px}\n.td-sz .shr-t{min-width:36px;text-align:right}\n.td-sz .shr-bg{display:block;width:60px;height:8px;background:var(--border);border-radius:4px;overflow:hidden;flex:none}\n.td-sz footer{color:var(--slate);font-size:12.5px;text-align:center;margin-top:30px}\n.td-sz .scroll{overflow-x:auto}\n'.strip()
_APP_LINKS = False

_esc

_esc(x) -> str

_f

_f(v)

A plain float, None for NaN / None.

_iso

_iso(t) -> str

_day

_day(t) -> str

_dom_where

_dom_where(dom: str) -> str

processes_sql

processes_sql(dom: str) -> str

The processes of the data domain (the public process catalog view applies the valid time).

process_ids_sql

process_ids_sql(dom: str)

The ids of the domain's processes as a sub-select that stands for the id list of the execution readers.

features_sql

features_sql(dom: str) -> str

The features of the domain at the current valid time (their storage tables).

calendar_rules_sql

calendar_rules_sql() -> str

The calendar rules stored for the tables of dates (small table).

table_sizes_sql

table_sizes_sql() -> str

The size of every storage table of the store, summed over the AMPs (narrowed in Python).

platform_sql

platform_sql() -> str

Number of AMPs and the Vantage version, in one row.

calendar_dates_sql

calendar_dates_sql(table_db: str, table: str) -> str

storage_sql

storage_sql(db: str, table: str, pids) -> str

Rows of a storage table per (process, ValidStart), read in one pass of the table.

The rows of the domain's processes are grouped by (FEATURE_VERSION, ValidStart); every other row falls in one group ('*', NULL), so the sum of the counts is the number of rows of the table, history included (what the bytes per row are divided by) and no second pass is needed. O counts the rows still open now.

first_statements

first_statements(dom: str, days: int, end) -> dict

R1: {name: statement} of everything read before the storage tables are known (pure but for the one cached available() probe of the execution tables).

collect_domain_sizing

collect_domain_sizing(data_domain, *, days: int = 365, horizon: str = 'quarter', storage: bool = True, emit=None) -> dict

Read what :func:build_domain_sizing needs. Only I/O, fail-open, TWO grouped requests.

  • R1 (nothing is known yet): the processes of the domain, its features (storage tables), the clock setting, the calendar rules, the executions (stored history + the live follow-up <-> DBQL join, for the domain's processes through a sub-select, the SQL of read_execution_resources), the lineage rows, the size of the store's FS_T_* tables and the platform (AMPs, version).
  • R2 (needs R1's tables and clock): the dates of the clock and, when storage is true, one statement per storage table of the domain (see :func:storage_sql).

The storage shape was chosen on Vantage 20 by reading the EXPLAIN steps (not counting them): see STORAGE_SHAPE (top of this module) for the measured choice.

Every failed read is recorded whole in errors ({"what", "message"}) and the part is left empty: nothing is raised. A statement that fails alone splits its request (degraded: more requests, requests_sent says how many were really sent). Returns a dict of frames and rows (not JSON-safe by design).

_quantile

_quantile(vals, q)

_stats

_stats(vals) -> dict

_wall_seconds

_wall_seconds(values)

Epoch seconds (zone dropped) of a list of dates, NaN where unreadable.

_digraph

_digraph(rows)

_waves

_waves(data, procs) -> dict

{available, reason, waves, wave_of, unknown, cycle} from the lineage rows and the process frame.

_calendar_of

_calendar_of(data)

(Calendar | None, inferred, reason) for the clock of the domain.

_theil_sen_trend

_theil_sen_trend(vals)

Slope per step of the usable values (None under MIN_STEPS values).

_forecast_at

_forecast_at(points, future_ts, horizon, gap_days=None) -> dict

Forecast of points at the given future times (epoch seconds). Same method and summary keys as :func:process_evolution.forecast_series, but the dates come from the clock's calendar.

_future_times

_future_times(points, cal, horizon)

(future epoch seconds, gap_days, source): the clock's next dates within the horizon, else one median gap apart.

_step_tables

_step_tables(execs, pids)

{metric: {pid: {t: point}}} and the measured span per step, from the timed executions.

build_domain_sizing

build_domain_sizing(data: dict, horizon: str = 'quarter') -> dict

The sizing model from :func:collect_domain_sizing's data. Pure; JSON-friendly. See the module docstring.

Never fabricates: under :data:MIN_STEPS usable steps a series has no forecast, with the reason.

_storage

_storage(data, model, procs, steps_t, view_of) -> dict

Rows and bytes per step from the stored GROUP BY rows: {by_step, summary}.

_scheduling

_scheduling(model, cal, inferred, data) -> dict

The refresh against the time between two steps of the clock.

pe_format

pe_format(v, unit)

_processes_table

_processes_table(model, pids, view_of, per, spans, wv, sto, steps_t)

One row per process: share of a step, trend, rows and bytes per step, tables, wave.

_fmt_bytes

_fmt_bytes(v)

_findings

_findings(model)

_svg_lines

_svg_lines(lines, *, unit='sec', title='', width=860, height=300, now_label='now (last step)') -> str

Several series over time. lines: [{name, color, points: [(t, y)], future: [{t, y, lo, hi}], dash}].

_cost_chart

_cost_chart(model) -> str

_storage_chart

_storage_chart(model) -> str

render_domain_sizing_html

render_domain_sizing_html(model: dict, *, app: bool = False) -> str

One self-contained HTML document (inline SVG and CSS, no script) from :func:build_domain_sizing.

app=True returns a fragment (scoped style + the report) for the admin app, with process names that open the object menu; the exported file (default) is unchanged.

_fragment

_fragment(doc: str) -> str

The scoped style (without the page-level body rules) and the report body of :func:_page.

_render_html

_render_html(model: dict) -> str

_page

_page(body, dom) -> str

_fc_cell

_fc_cell(model, key, unit) -> str

_summary_table

_summary_table(model) -> str

_storage_table

_storage_table(model) -> str

_sched_html

_sched_html(model) -> str

_other_series

_other_series(model) -> str

_pct

_pct(v, signed=False) -> str

_count

_count(v) -> str

_obj_attrs

_obj_attrs(p) -> str

Attributes that make a process name open the app's object menu (only when rendered for the app).

_process_table_html

_process_table_html(model) -> str

_small_multiples

_small_multiples(model) -> str

_to_t

_to_t(x) -> float

render_domain_sizing_markdown

render_domain_sizing_markdown(model: dict) -> str

The same model as Markdown tables (no chart).

domain_sizing_csv

domain_sizing_csv(model: dict, what: str = 'steps') -> str

CSV of the per-step table (what='steps') or of the process table (what='processes').

domain_sizing

domain_sizing(data_domain=None, horizon: str = 'quarter', days: int = 365, storage: bool = True, emit=None) -> dict

Size a data domain: the cost of one refresh (one step of its clock), how it evolves, the storage each step adds and a forecast over horizon ('month', 'quarter', 'semester', 'year'). Read only: two grouped requests, nothing is written. storage=False skips the storage scan (the expensive part: one pass over each storage table). Returns the model :func:build_domain_sizing builds (see :func:render_domain_sizing_html).

write_domain_sizing_report

write_domain_sizing_report(data_domain=None, out_path: Optional[str] = None, fmt: str = 'html', *, model: Optional[dict] = None, what: str = 'steps', **kwargs) -> str

Write the sizing report of a data domain and return its path. fmt: 'html' (default, self-contained), 'md' or 'csv' (what='steps' or 'processes'). kwargs go to :func:domain_sizing; model renders a model already built. Default folder: tdfs4ds.DASHBOARD_REPORT_DIR.