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', 'N_EXPECTED_ERRORS')
_CLIENT_STORE
module-attribute
¶
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.
With call_id: the statements and phase time of that call only (no other row of
the block: time outside a call belongs to no call).
_Snapshot
¶
Bases: Profile
The kept client summary of one call: its per-phase frame and when its block ended. Behaves as
the Profile it came from for :func:run_profile (no statement list is kept).
client_profile
¶
The client summary kept for call_id by the last :func:profile block that made the call
(this process only), or None.
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.
client_summary
¶
The client side alone, when the database figures are not there yet. Pure on the frame:
{"statements", "statement_sec", "python_sec", "wall_sec", "text"}.
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).
_kept_client
¶
The client summary kept by :func:profile for every id of ids (merged by phase when several),
or None as soon as one is missing.
flush_query_log
¶
FLUSH QUERY LOGGING WITH ALL: ask the database to write DBQL's cache now. Needs the right
for it (EXECUTE on the statement; denied for most users). Fail-open: {"flushed", "error"}.
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'.
Without client, the summary a :func:profile block of this process kept for the call id is used
(the last 200 calls, CLIENT_STORE_MAX): reading the call after DBQL's flush, in the same
session, gives the verdict without the Profile object. While DBQL is PENDING the client side
is reported at once (info["client_summary"]) and the database figures follow. flush: first issue
FLUSH QUERY LOGGING WITH ALL (never done by default; only works for a user who has the right;
info["flush"] says what happened).
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.