Shared performance metrics collection#
Shared collection and exposure#
Performance measurements are collected before selecting their output. The
backend-independent PerfMetricsCollector creates owned immutable
PerfMetricsRecord values with three categories:
Category |
Measurements |
|---|---|
|
Candidate-completion latency/tokens/cache metrics, or explicitly enabled diagnostic request iteration records. Diagnostic request records are not a second completion stream. |
|
Completed-batch iteration data and separately identified loop-boundary observations: host/device timing, scheduled/active/unscheduled/dummy work, fetched requests, and model state. |
|
Rank-owned KV snapshots, memory and capacity limits. Actual snapshot capture iteration/time remain explicit; |
Request and iteration records also retain their source rank. A delayed batch
record and its attached executorLoop can describe different iterations under
overlap or pipeline parallelism. The loop has its own iteration, rank and
loopSequence; the sequence advances even while the executor iteration counter
is stalled. Free-form model state and iteration identifiers remain diagnostic
data, not Prometheus labels.
LoggerExposure formats collected loop records in the executor thread using
the existing single-line iteration format, including KV block reuse counters.
num_fetched counts requests assigned since the previous emitted line, including
loops skipped by iteration sampling. Rank snapshots and request diagnostics stay
available through the statistics transport without additional JSON log lines.
PrometheusExposure is the long-lived serving-side adapter. HTTP and OpenEngine
normalize transported records through the same category model before exposing
them. MetricsCollector, log_iteration_stats and log_request_metrics_dict
remain compatibility interfaces. Scraping and idle periods do not trigger
source reads, reset counters or require an active request.
Neither exposure reads an executor/KV manager or drains native events. Source
collection alone owns those operations. When batch stats are enabled, the loop
logger reuses collected rank snapshots without an additional KV query. In
logger-only mode the collector retains the existing basic-KV refresh cadence
of 16 loop boundaries on selected logging ranks. Detailed KV/tier collection
still requires enable_iter_perf_stats; enabling text alone does not enable
all expensive request/tier diagnostics.
Use case |
Existing controls |
|---|---|
Production Prometheus |
|
Offline iteration text with basic KV utilization |
|
Iteration text with detailed statistics transport |
|
Both outputs |
Enable iteration text alongside production collection; source reads and instrumentation are shared |
This separation adds record construction/serialization and optional logging work. It introduces no CUDA events or synchronization beyond the existing collection/timing settings. The existing device-step profiler timing policy is preserved. CPU and end-to-end overhead of this refactor have not been benchmarked.
Prometheus#
Enable production collection using the serving configuration above. Set
iter_perf_stats_interval: 1 for unsampled iteration records.
trtllm-serve /path/to/model --config metrics.yaml --port 8000
curl --fail http://localhost:8000/prometheus/metrics
Scrape each worker separately. OpenEngine uses a
separate metrics listener.
Set request histogram buckets in seconds through prometheus_metrics_config.
Transfer outcomes.
trtllm_kv_cache_transfer_requests_totalcounts success, error, and timeout once per transfer on each reporting rank. CTX sends and GEN receives count their own endpoints. User cancellation alone is excluded.trtllm_kv_cache_transfer_duration_secondsandtrtllm_kv_cache_transfer_bytes_totaluse completed generation-side request observations. Bytes cover the receiving rank that reports the request.Tier capacity and movement.
trtllm_kv_cache_tier_{blocks,bytes}reports free, evictable, and unavailable capacity per level and pool group. The exported unavailable remainder includes retained cold copies that can be reclaimed.trtllm_kv_cache_tier_moved_{blocks,bytes}_totalcounts accepted restores, evictions, and drops. Evictions count changes in residency, including reuse of retained copies. Its byte totals use logical slot sizes. Detailed tier snapshots report rank 0 under attention DP.Conversation activity.
trtllm_kv_cache_num_conversationscounts retention entries, including saved plans.trtllm_conversation_unique_seencounts distinct conversation identities admitted by a worker in rolling10mand1hwindows. Workers can see the same identity, so summing their counts can double-count it. Usetrtllm_conversation_unique_seen_completeto identify full windows. The fixed limits are 100,000 distinct identities and 16 MiB of accounted identity storage. Capacity skips incrementtrtllm_conversation_tracking_overflow_total. The exporter updates these gauges when it drains iteration stats, including idle heartbeats.Executor timing. Host and GPU forward histograms observe measured rank-0 iterations. The previous device-step gauge lags by one loop. Per-loop work metrics use the producing
global_rank. Attention DP publishes loop metrics from rank 0.
Transport cost and KV utilization semantics#
Worker serialization parses native JSON into a dictionary, partitions it into owned immutable categories, and encodes the existing JSON transport shape. The consumer still parses that JSON. Parsing the native JSON and encoding/decoding the wire payload were already required; partitioning, recursive freezing and mapping adaptation add CPU work. The worker’s freeze runs on the transport thread. Source snapshot freezing and loop-record construction also run on the executor thread.
The pending overhead benchmark must cover both source collection and transport: compare baseline and refactored CPU time/allocations per record and transport throughput with request diagnostics disabled/enabled, varying request counts, KV snapshot sizes and rank counts. Separately compare logger-only, Prometheus-only and combined outputs in an inference workload. No measured overhead claim is made before those checks run.
KV utilization prefers an explicit usedNumBlocks value, including measured zero.
For basic snapshots without that field, it uses maxNumBlocks - freeNumBlocks.
Missing or non-positive capacity produces unavailable utilization (N/A in the
iteration log). This preserves the logger-only free-block calculation and its
zero-capacity N/A behavior. Prometheus retains its existing requirement for
explicit used blocks and positive capacity; it does not infer a utilization series
from a free-only snapshot. Reclaimable cached prefixes can remain in available
blocks, so utilization alone does not measure conversation-cache retention.
Create a Grafana dashboard#
The Grafana setup example
provides a standard-library Python renderer and publisher for Kubernetes serving.
It discovers engine workers and has E2E, Prefill, Decode and All views. Configure
your workload pod/job patterns, datasource UIDs, endpoint/container labels and
Grafana’s supported schema-v2 API version in a copy of example.config.json.
The default configuration generates metrics only; the logs dashboard,
scrape-resource creation and trace-PVC panels are optional.
cp examples/serve/grafana/example.config.json /tmp/trtllm-dashboard.json
# Edit the copied configuration for your deployment.
python3 examples/serve/grafana/dashboard.py render \
--config /tmp/trtllm-dashboard.json --output /tmp/trtllm-dashboard-rendered
python3 examples/serve/grafana/dashboard.py deploy \
--config /tmp/trtllm-dashboard.json --output /tmp/trtllm-dashboard-rendered --dry-run
Rendering is offline. The deployment dry-run validates the selected Grafana API
and enabled Kubernetes resources without publishing them. Run deploy without
--dry-run to publish. Use API persistence for API-owned dashboards and
configmap-v2 for existing file-sidecar ownership; applying its generated ConfigMap
alone is incomplete. The tool guards resource versions and reads back saved
content. ConfigMap checkpoint plus native finalization is not a cross-system
transaction; the README documents --finalize-only recovery.
The default dashboard shows tier occupancy, restore and eviction turnover, final drops, and completed-request transfer duration. Native ratios use logical byte capacity and remain separated by level, tier, and reporting rank. Unsupported observations hide optional panels. GPU available blocks can include reclaimable prefixes. These panels cannot identify which prefix was evicted.
Select one application scrape job path to avoid duplicate engine observations.
Existing irate charts use the last two samples in counter_lookback. Tier
turnover charts average the window. Dashboard creation does not enable instrumentation.