Skip to content

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

For one call, tdfs4ds.profile() and tdfs4ds.run_profile() give the client and the database side. 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 staging CREATE 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: see tdfs4ds.profile().
  • MECHANISM is client today. It is set by the optional band key TDFS4DS_MECHANISM when 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 eight questions:

  1. Fixed or variable? Per process, a robust fit cost = a + b x rows over its calls: a is the fixed cost of a step, b the cost per 1,000 rows, and the break-even is the volume below which the framework costs more than the work.
  2. Where does the fixed cost go? Statements and database time by phase, safety checks highlighted.
  3. 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.
  4. Volume classes. The framework share by rows written per step.
  5. Per call kind. run, roll_out, registration (upload).
  6. Trend by package version. Framework statements per step before and after an upgrade.
  7. The heaviest framework phases, each with what cuts it.
  8. 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_profile call to look closer.

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:

tdfs4ds.register_framework_monitoring(data_domain='FS_MONITORING', run_now=True)

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.