Measure what the framework costs¶
A tdfs4ds call sends dozens of statements. Some are the work you asked for (the ingestion, the MERGE, the statistics). The others are the framework: catalog reads, safety checks, follow-up rows, the TimeManager cursor. On a system far from the client, each statement costs a round trip, so the framework can cost more than the work. This page shows how to measure it, store the measure, read it, and forecast it.
Nothing here changes what a call does. It reads what the database already logged.
What is measured¶
Every statement a call sends carries a phase (compute, merge, stats, catalog, uniqueness, followup...)
and the call's id, through a comment and the session query band. The database logs them (DBQL). Three groups:
| Group | Phases | Meaning |
|---|---|---|
| work | compute, merge, stats, close_absent, dataset |
What you pay for |
| safety | upstream, history_guard, uniqueness, null_key, row_count, truncation |
Checks that guard correctness: a cost to know, not to switch off |
| framework | the rest (catalog, options, clock, followup, registration...) |
What the framework needs around the work |
What each label means¶
The report's bar charts and tables name the phase of each statement. In the report, hover a bar for its explanation; under the charts, What the labels mean lists the phases that are drawn.
| Phase | Kind | What it covers | How to reduce it |
|---|---|---|---|
compute |
work | Your source query, run once per execution into a staging table (CREATE VOLATILE TABLE AS over the process view), plus the UAF ART statements. Every run. | Optimise the process view (primary index, partitioning, FilterManager); this is the work itself. |
merge |
work | The MERGE (or UPDATE+INSERT) of the staged rows into the FS_T_ feature tables. Every run that has rows. | Nothing to cut: fewer changed values means fewer rows written. |
stats |
work | COLLECT STATISTICS on the feature tables after the ingestion (apply_collect_stats). Every run that computed something. | Skipped when the run computes nothing. STATS_BASE_USING sets the sampling of base statistics. |
close_absent |
work | Ends the validity of entities the process no longer produces (volatile key table, sequenced DELETE). Only when close_absent_entities is on. | close_absent_entities=False if the source never drops entities. |
dataset |
work | build_dataset / build_historical_dataset, and the dataset a run builds when dataset_view_name is given: the view, its catalog rows and optional documentation. | Build the dataset once, not per run (leave dataset_view_name unset on routine runs). |
upstream |
safety | check_upstream=True: loads the lineage graph and the follow-up of the upstream processes to refuse a run whose input FAILED. Only when check_upstream is on. | check_upstream=False when the order is guaranteed elsewhere. A safety check: its cost is the price of the refusal. |
history_guard |
safety | roll_out only: before the first date, reads where each process's stored history starts so a replay is not begun after it (a history is built forward only). Once per roll_out call; skipped for valid_time_column processes. | Nothing to cut: it prevents a wrong history. |
uniqueness |
safety | One statement on the staged table: rows staged, duplicate entity keys and NULL key columns (it also reads a few duplicated keys when it finds some). Every run. | Nothing to cut: it protects the primary index. A very large staging table makes it longer. |
null_key |
safety | The NULL entity-key check. Since 0.3.8.0 it is part of the one staging statement counted under uniqueness, so this label stays empty on current versions (old history only). | - |
row_count |
safety | A separate COUNT of the staged rows, used only when the staging check did not report them. Normally empty. | - |
truncation |
safety | One aggregate on the staged rows: is a text value longer than the stored VARCHAR? Only for registered VARCHAR features whose source is longer than the stored type. | Widen the stored type with plan_type_change, or CAST in the view. |
catalog |
framework | Reads of the process, feature and dataset catalogs, the feature ids and types, and the metadata teradataml reads when it opens the process view as a DataFrame. Every run. | Fewer processes per roll_out call (roll_out reads catalog rows once per call). |
options |
framework | Reads of the process options (FS_PROCESS_OPTIONS, FS_PROCESS_SETTINGS: close_absent_entities, track_entity_refresh, valid_time_column, force_varchar_length...) and the domain's process list. Once per process per call. | roll_out already prefetches them once per call; nothing else to set. |
clock |
framework | Resolving the valid time of the run (TimeManager date, domain clock, database clock), moving TimeManager cursors, soft clones, and the pairing written at registration. | One clock per data domain (set_domain_time_manager) and roll_out(data_domain=...). |
skip_check |
framework | Decides whether a (process, date) is already COMPLETED in FS_FOLLOW_UP (one COUNT, or one grid read per roll_out). A date already done costs only this. | Nothing to cut; roll_out reads the whole grid once per call. |
filter |
framework | FilterManager work: building the manager, moving it to each segment (update) and reading the segment's row. Once per segment. Only for processes with a FilterManager. | Fewer, larger segments (each segment is a full ingestion), or no FilterManager. |
followup |
framework | The execution log: one row opened and one closed in FS_FOLLOW_UP per execution (or per segment). Every run. | Fewer executions: fewer segments or dates. |
entity_refresh |
framework | Records that each entity was confirmed in this run (FS_R_ table). Only when track_entity_refresh is on. | track_entity_refresh=False when the last-seen date per entity is not needed. |
lineage |
framework | Records the lineage edges of the process view (SHOW VIEW of each object in the chain) at registration. Registration only. | Register once, not per run (an unchanged re-registration skips the writes). |
sql_capture |
framework | Captures the SQL beneath the process view (SHOW VIEW chain, hash, FS_PROCESS_SQL) to version it: at registration and once per run call. | PROCESS_SQL_VERSIONING=False turns it off (versions are then not kept). |
registration |
framework | upload_features: checking the source view, the storage definition probe, the process catalog rows, entity and feature registration, storage tables. Registration only. | Register once, then run(); an unchanged re-registration is cheaper (SKIP_UNCHANGED_REGISTRATION). |
documentation |
framework | The documentation upload_features writes when document is on: an LLM pass over the process and its lineage chain (many SHOW VIEW, EXPLAIN and dictionary reads and writes), the dataset documentation and the vector index refresh. Registration only. | document=False (UPLOAD_DOCUMENT) and vector_indexing=False for fast registrations; document later with rebuild_documentation. |
optimize |
framework | The optional query optimiser at registration (EXPLAIN of candidate rewrites). Registration only, when optimize_query is on. | optimize_query=False (the default, UPLOAD_OPTIMIZE_QUERY). |
query_band |
framework | The statements that read, set and restore the session query band (TDFS4DS_CALL_ID, execution tags): 3 per call plus the ones per execution, so statements can be joined to DBQL. | QUERY_BAND=False removes them (and the profile with them). |
history |
framework | The copy of DBQL into FS_EXECUTION_RESOURCES and FS_CALL_PHASES, started at the top of run() and roll_out(), at most every 10 minutes per Python process. Few statements, but each reads DBQL (DBC.QryLogV, a large dictionary view): this is why it can dominate database seconds. | EXECUTION_RESOURCES=False and PHASE_TAGS=False stop the copies; run less often. |
other |
framework | Statements sent inside a call but outside any phase block, plus the statements never tagged (CREATE/REPLACE VIEW, such as a TimeManager or FilterManager cursor move). A big share here means untagged framework work. | - |
Two surprises are normal. history can dominate the database seconds with only a few statements: it is the copy of DBQL into the history tables, and each statement reads a large dictionary view. documentation can dominate the statement count of a registration: the documentation pass reads the whole lineage chain of the process and writes dictionary rows (switch it off with document=False).
For one call, tdfs4ds.profile() and tdfs4ds.run_profile() give the client and the database side.
profile() keeps each call's client summary (the last 200 calls of the process), so run_profile(call_id) works
later in the same session without the object; while DBQL has not written yet (PENDING, it flushes about every
10 minutes) the client side is given at once and the database figures follow. run_profile(call_id, flush=True)
issues FLUSH QUERY LOGGING WITH ALL first, only for a user who has the right (otherwise it says so and goes on).
N_ERRORS counts every statement in error. Some fail by design: a DROP of a temporary table that is not there, the
first COLLECT STATISTICS of a table, a SHOW VIEW on a name that is a table, teradataml's HELP INDEX on a view and
its ABORT. run_profile reports N_EXPECTED_ERRORS apart ("nothing unexpected", or how many are), and the optional
table FS_CALL_PHASE_ERRORS with its view FS_V_CALL_PHASE_ERRORS keeps the split per call and phase (a call
harvested before 0.3.8.1 reads NULL, not 0).
FS_CALL_PHASES keeps the database side of every call, so you can compare calls over weeks.
Keep the history¶
FS_CALL_PHASES is an optional table, created by setup() and connect() when the user may create tables. It is
filled by the harvest that run() and roll_out() already start (at most every 10 minutes): one more
INSERT ... SELECT inside the database, nothing sent from the client, nothing added to your run. A call is stored
once DBQL has flushed it (10 minutes by default).
Prerequisites: query logging on for the user (BEGIN QUERY LOGGING WITH SQL ON <user>;) and SELECT on DBC.QryLogV.
import tdfs4ds
# Harvest now rather than waiting for the next run
tdfs4ds.harvest_execution_resources()
steps = tdfs4ds.framework_cost('run', days=30, as_pandas=True) # one row per call and process
daily = tdfs4ds.framework_cost('daily', data_domains=['SALES']) # a teradataml DataFrame
| Object | One row per | Use |
|---|---|---|
FS_V_CALL_PHASES |
call x process x phase | The facts, with PHASE_GROUP |
FS_V_FRAMEWORK_COST_RUN |
call x process | The step's framework, safety and work statements and database time, ROWS_WRITTEN, FIXED_COST_RESIDUAL |
FS_V_FRAMEWORK_COST_DAILY |
day x process x phase group | A regular series, zero-filled between the first and the last call of a process |
What the figures are, and are not:
- A step is one execution of a process. A call with no execution (a registration) counts one step.
- Rows are the feature rows the MERGE wrote (
StmtDMLRowCount). DBQL has no row count for the stagingCREATE TABLE AS, and a re-run that changes nothing writes no row. - A statement outside an execution has no process. When a call touched exactly one process, those statements are
attributed to it; otherwise they are shown as
CALL_LEVEL. - Times are the database's (
FirstRespTime - StartTime). The round trip is the client's: seetdfs4ds.profile(). MECHANISMisclienttoday. It is set by the optional band keyTDFS4DS_MECHANISMwhen a server-side batch exists.
The report¶
Performance > Framework cost in the admin app, or in Python:
path = tdfs4ds.write_framework_cost_report('framework_cost.html', days=90) # fmt='csv' for the step table
It answers ten questions:
- Fixed or variable? Per process, a robust fit
cost = a + b x rowsover its calls:ais the fixed cost of a step,bthe cost per 1,000 rows, and the break-even is the volume below which the framework costs more than the work. - Where does the fixed cost go? Statements and database time by phase, safety checks highlighted.
- Latency or work? Statements x round trip against database time, with a what-if of the round trip (450 ms, 50 ms, 5 ms, or the slider). A latency-bound process gains from fewer statements or from running closer to the database; a work-bound one from its SQL, primary index and partitioning.
- Volume classes. The framework share by rows written per step.
- Per call kind.
run,roll_out, registration (upload). - Trend by package version. Framework statements per step before and after an upgrade.
- The heaviest framework phases, each with what cuts it.
-
Anomalies. A step whose framework statements or time is more than 3.5 robust deviations (median / MAD) above its process's last 60 steps, with the phase that moved most and the
run_profilecall to look closer. -
Framework against the workflow. The same window, split into four roles: your SQL, tdfs4ds work, safety checks and framework, with the ratio (framework + safety) / your SQL, for statements, database seconds and AMP CPU, by origin, by call kind and by process. Your SQL is the staging
CREATE VOLATILE TABLE ASover the process view of each execution (phasecompute, plus UAF ART statements): the only statements whose cost the user's own query decides. The MERGE, the statistics and the dataset builds are tdfs4ds work. A call that touched several processes shares its call-level statements (CALL_LEVEL). - Which phases, by origin. Each phase by statements and database seconds for each origin of the call.
Origin. A call is app when a person of the admin app is named on it (TDFS4DS_APP_USER, set by the login
gate; it is on every statement of the call since 0.3.8.12). Otherwise its kind decides: upload_features,
roll_out, run, build_dataset (build_dataset and build_historical_dataset share the kind dataset), or other.
Without the login gate the app cannot be told apart from a notebook.
What cannot be attributed. Only statements carrying a call id are kept in FS_CALL_PHASES. The admin app's own
reads (reports, panels) and the cost-history copy a panel starts are sent outside any call, so they are not in the
history at all: the big history bar is the copy started by run() inside an upload_features or other banded
call, at most every 10 minutes, not the app's reports. A direct run() or roll_out starts its own copy before its
band opens, so that copy is not recorded either. Your own SQL outside tdfs4ds calls is not counted.
The round trip is measured on demand (SELECT 1 five times on a connection of the app's own).
Opt-in speed settings¶
When the profile says a call is latency-bound (many cheap statements, the database seconds small next to the wall time, a client far from the database), three settings cut the wall time without changing the result. All three are off by default: with them off the statements, the stored values, the follow-up rows and the return values are exactly those of the release before.
| Setting | What it does | When |
|---|---|---|
tdfs4ds.GROUP_BATCH_STATEMENTS = True (env TDFS4DS_GROUP_BATCH_STATEMENTS) |
The MERGEs of one batch go in one multi-statement request instead of one request each. The follow-up row stays separate and is written first, so a failure still ends the batch FAILED. |
A process with several storage tables per batch. |
roll_out(..., max_workers=N) |
The processes of one date that do not depend on each other (same wave of the parallel plan) and do not write the same table run in up to N worker OS processes, each with its own session. Dates stay sequential, the cursor is moved by the parent as before. The workers open their session from TDFS4DS_TD_* (a token works); without them roll_out refuses before running anything. |
A roll-out of many processes over many dates from a remote client. |
tdfs4ds.SERVER_SIDE_BATCH = 'auto' (env TDFS4DS_SERVER_SIDE_BATCH) |
The MERGEs of a batch run in one CALL of a generic stored procedure (TDFS4DS_RUN_BATCH_<version>, dynamic SQL, same statements, same order, same session). |
A high round-trip time and a database where you may create a procedure. |
The server-side batch needs an object in your database, so it is installed on purpose and reviewed first:
import tdfs4ds
r = tdfs4ds.install_server_side_batch() # dry run: the statements, nothing executed
print("\n".join(r["statements"]))
# tdfs4ds.install_server_side_batch(dry_run=False) # creates the procedure and records its text
tdfs4ds.SERVER_SIDE_BATCH = 'auto'
tdfs4ds.check_configuration(only=['server_side_batch']) # installed? rights? (probe_writes=True tries a throwaway)
If the procedure is missing, cannot be executed or a statement cannot run inside a procedure, one warning is
logged, the mechanism is off for the session and the same batch continues statement by statement (the follow-up
row already open is reused; the MERGEs are idempotent). A data error inside (duplicate key, cast error) fails the
batch exactly as it does without the setting, with the database's own message in the FAILED status. The sanity
check server_batch reports a missing, drifted, stale or unregistered object, each with its fix; the app tab
Performance > Server-side batches shows the objects, their text and the SQL they replace (read-only; the install
script is a download, never a button). get_process_info(...)['SERVER_BATCH'] shows the setting.
A per-process macro was considered and is not used: the statements of a batch name the staging table (new at
every batch) and carry the valid time as a VALIDTIME PERIOD literal, and a macro takes parameters for values only,
never for identifiers or a temporal qualifier. SERVER_SIDE_BATCH = 'macro' is accepted and behaves like 'auto'.
Re-run tdfs4ds.profile() with the setting on and off and compare: the statement count and the wall time are what
to judge. The framework-cost report labels the mechanism of each call (client / procedure).
Store it as features¶
The cost history can itself be stored as features, with history, lineage and time travel from the store:
It registers two process views over FS_V_FRAMEWORK_COST_DAILY in the data domain you give, and writes only there:
FS_MON_FRAMEWORK_BY_PROCESS (entity PROCESS_ID: framework_statements_per_step, framework_sec_per_step,
work_sec_per_1k_rows, safety_share over the last 28 days) and FS_MON_FRAMEWORK_BY_DOMAIN
(entity MONITORED_DOMAIN: domain_framework_share, domain_calls). Drive them like any process, with run()
or a domain clock. It is off by default.
Forecast it¶
A recipe, not a feature of the app: a forecast needs months of daily history, and a new FS_CALL_PHASES has none.
With at least a few months, forecast the next 30 days of database time per data domain from
FS_V_FRAMEWORK_COST_DAILY, in the database, with the UAF operators (see the td-uaf-forecast skill):
-- Daily framework + safety database seconds of one data domain, a regular series
CREATE VOLATILE TABLE fc_series AS (
SELECT DAY_DATE, SUM(DB_ELAPSED_SEC) AS DB_SEC
FROM <store>.FS_V_FRAMEWORK_COST_DAILY
WHERE DATA_DOMAIN = 'SALES' AND PHASE_GROUP <> 'work'
GROUP BY DAY_DATE
) WITH DATA PRIMARY INDEX (DAY_DATE) ON COMMIT PRESERVE ROWS;
-- Fit an ARIMA model (choose the order with TD_ACF / TD_PACF first), then forecast 30 days
EXECUTE FUNCTION INTO VOLATILE ART(fc_art)
TD_ARIMAESTIMATE(
SERIES_SPEC(TABLE_NAME(fc_series), ROW_AXIS(TIMECODE(DAY_DATE)), SERIES_ID(DAY_DATE),
PAYLOAD(FIELDS(DB_SEC), CONTENT(REAL))),
FUNC_PARAMS(NONSEASONAL(MODEL_ORDER(1,1,1)), CONSTANT(1), ALGORITHM(MLE), FIT_PERCENTAGE(100)),
OUTPUT_FMT(INDEX_STYLE(NUMERICAL_SEQUENCE)));
SELECT * FROM TD_ARIMAFORECAST(
ART_SPEC(TABLE_NAME(fc_art)), FUNC_PARAMS(FORECAST_PERIODS(30), CONFIDENCE_INTERVAL(95))) AS f;
The exact SERIES_SPEC of your calendar (a DATE axis needs the timecode type of your system) is in the
td-uaf-forecast skill. Treat the output as a trend line: an upgrade that removes statements is a step the model
cannot foresee, which is what the trend by version and the anomalies are for. This SQL was not run on a store with
months of history: check the SERIES_SPEC against the skill before relying on it.