tdfs4ds.profiling¶
tdfs4ds.profiling
¶
Where a tdfs4ds call spends its time: profile() (client) and run_profile() (database) (0.3.8.0).
::
with tdfs4ds.profile() as p:
tdfs4ds.roll_out(...)
p.report() # statements and time per phase, client side
tdfs4ds.run_profile(p.call_ids[0], client=p) # + DBQL: DB time, CPU, I/O, spool, skew; verdict
Three kinds of time are told apart (they need different cures):
- DB time: DBQL
FirstRespTime - StartTimeof the statements (the database working); - wire time: the client's time in the statement minus its DB time (round trip, transfer);
- Python time: the wall time of the phase minus the time inside its statements (teradataml, pandas, tdfs4ds code between two statements).
A call dominated by wire time is latency-bound: fewer statements, or running closer to the
database, help; better SQL does not. A call dominated by DB time is work-bound: SQL, primary
index, partitioning. The phases are named by tdfs4ds.utils.phases (see its docstring for the
contract: tag format, names, groups, and the SQL helpers to read them from DBQL).
DBQL writes from a cache (10 minutes by default): a call that just ended reads PENDING
with the time to retry. A DBQL that cannot be read, or does not log the user, leaves the client
side alone with state saying why (same handling as read_execution_resources).
DB_COLUMNS
module-attribute
¶
DB_COLUMNS = ('DB_STATEMENTS', 'DB_SEC', 'AMP_CPU_SEC', 'IMPACT_CPU_SEC', 'CPU_SKEW_PCT', 'TOTAL_IO', 'IO_SKEW_PCT', 'MAX_SPOOL_BYTES', 'ROWS_RETURNED', 'N_ERRORS')
Profile
¶
What :func:profile yields. counts is the underlying StatementCount;
call_ids the ids of the tdfs4ds calls made inside the block (outermost calls).
by_phase
¶
One row per phase: statements, statement_sec (client time inside the
statements), wall_sec (the phase's own wall time), python_sec (wall minus
statements). The other row takes the wall time outside every phase block.
profile
¶
Profile what a block sends to the database, by phase (see the module docstring).
Built on count_statements(timings=True) plus the phase blocks of tdfs4ds.utils.phases;
adds nothing to the statements. Yields a :class:Profile.
run_profile_sql
¶
The DBQL read behind :func:run_profile: one row per phase of the call(s). Pure.
latency_verdict
¶
Latency-bound or work-bound? Pure. Shares are of wall_sec (>= statement time).
{"kind": 'latency' | 'work' | 'client' | 'unknown', "db_share", "wire_share",
"python_share", "wire_ms_per_statement", "text"}.
merge_phases
¶
Join the client frame (Profile.by_phase(), may be None) and the DBQL frame (may be None)
on the phase. Pure on frames. Adds wire_sec = client statement time - DB time.
_numeric
¶
The driver returns DECIMAL as decimal.Decimal: measures become float (None -> NaN).
run_profile
¶
The cost of one tdfs4ds call by phase, from DBQL, merged with a client profile.
call_id: the id of the call (p.call_ids[0]), a list of ids, or None to take them from
client (a :func:profile object). client: the Profile (or its by_phase() frame) of
the same call: adds the client time, the round trip (client minus database) and the verdict.
fmt: 'frame' (pandas; frame.attrs holds info and verdict), 'text', 'html'.
info["state"]: OK; PARTIAL (the call's last statement is younger than DBQL's flush,
totals may grow); PENDING (nothing logged yet, retry_in_sec says when to ask again);
NOT_LOGGED / NOT_FOUND (old call, absent: logging off for the user, or not banded);
UNAVAILABLE (DBQL cannot be read: client side only, hint names the grant);
CLIENT_ONLY (no database read was possible or asked). Never raises on a DBQL failure.