DataSpanner

9 Key LLM Inference Metrics Explained in 5 Minutes

By Dataspanner Editorial · · 9 min read · AI Infrastructure

9 Key LLM Inference Metrics Explained in 5 Minutes — AI Infrastructure cover illustration

Introduction

Large Language Model (LLM) inference is rarely a single “run the model and return tokens” operation. In a production environment a request lands on a cluster of GPU‑based inference servers, may sit in a queue, travel across a network, and then stream tokens back to the client. The user’s experience is shaped by a handful of measurable dimensions—how long they stare at a blank screen, how quickly tokens arrive after the first, and how many requests the service can sustain while staying within latency limits.

For data engineers, these dimensions are not just academic; they dictate how you design monitoring pipelines, set service‑level objectives (SLOs), budget for GPU usage, and even choose the storage back‑end for inference telemetry. This article walks through nine practical LLM inference metrics, explains the math behind each, and adds a Dataspanner‑centric view of how to capture, store, and act on them in a real‑world system.


Understanding Latency: TTFT, E2E, and Token Generation

1. Time‑to‑First‑Token (TTFT)

What it is: The wall‑clock time from when a client sends a prompt until the first output token appears.

Why it matters: In interactive chat or generative UI, TTFT is the “blank‑screen” latency that users notice most. A 2‑second TTFT feels instant; a 10‑second TTFT feels sluggish even if the rest of the response is fast.

Formula:

TTFT = t_first – t_send

t_send – moment the request leaves the client
t_first – moment the first token arrives

2. End‑to‑End Latency (E2E)

What it is: Total time from request dispatch to receipt of the last token.

Why it matters: E2E captures the full user‑perceived delay, useful for batch‑style generation where the whole output matters.

Formula:

E2E = t_last – t_send

3. Token Generation Time (TokenGen)

What it is: The duration the server spends streaming tokens after the first one.

Why it matters: TokenGen isolates the “streaming” part of inference, helping you spot slowdowns that only appear once the model is already humming.

Formula:

TokenGen = t_last – t_first = E2E – TTFT

4. Time‑Per‑Output‑Token (TPOT)

What it is: Average interval between consecutive output tokens (excluding the first token).

Why it matters: TPOT normalizes TokenGen across responses of different lengths, giving a per‑token speed indicator.

Formula:

TPOT = (E2E – TTFT) / (N_out – 1)

If a response contains only one token, TPOT is undefined—use ITL instead.

5. Inter‑Token Latency (ITL)

What it is: The exact gap between token j and token j+1 for every pair in a request.

Why it matters: ITL preserves fine‑grained stalls. A single long gap shows up as a spike in ITL but may be hidden in an averaged TPOT.

Formula:

ITL_j = t_{j+1} – t_j   (j = 1 … N_out‑1)

Across many requests:

MeanITL = Σ_i Σ_j ITL_{i,j}  / Σ_i (N_i – 1)
MeanTPOT = (1 / R) Σ_i TPOT_i

Dataspanner perspective: When you store per‑token timestamps in Cloud Spanner, the MeanITL calculation can be pushed down using a single‑query aggregation, but be mindful of the N_out‑1 denominator exploding for long‑form generation (e.g., summarization of long documents).

6. Latency Percentiles

What they are: Statistical cuts (P50, P90, P99) of the latency distribution for TTFT, TPOT, or E2E.

Why they matter: Percentiles expose tail latency that can cripple user experience even when the average looks fine.

Nearest‑rank formula:

P_k = x_{( ceil(k/100 * N) )}

Common mistake: Computing a percentile per‑node and then averaging. That masks spikes on a single node; always aggregate raw samples across the whole cluster.


Throughput and Goodput: Measuring What the System Delivers

7. Requests Per Second (RPS)

What it is: Completed requests divided by observation window.

Formula:

RPS = N_completed / (t_end – t_start)

When to use: Compare runs that have identical prompt/response length distributions. If you mix long‑prompt research queries with short chat turns, RPS alone is misleading.

8. Tokens Per Second (TPS)

Two flavours are useful:

  • Output TPS – tokens emitted to the client.
  • Input TPS – tokens consumed from the prompt side.

Formulas:

TPS_out = Σ_i N_out_i / (t_end – t_start)
TPS_in  = Σ_i N_prompt_i / (t_end – t_start)

Dataspanner tip: Store both N_out and N_prompt in the same table (e.g., inference_log) and compute TPS with a single SQL aggregate. This avoids cross‑region joins that would add latency to monitoring dashboards.

9. Goodput

What it is: The rate of requests that satisfy your SLOs (e.g., TTFT ≤ 200 ms, TPOT ≤ 50 ms, E2E ≤ 2 s).

Formula (boolean condition):

Good_i = (TTFT_i ≤ s_ttft) ∧ (TPOT_i ≤ s_tpot) ∧ (E2E_i ≤ s_e2e)
Goodput = Σ_i Good_i / (t_end – t_start)

Why it matters: Goodput tells you how many useful requests you are actually handling, not just raw throughput. It is the metric that aligns with user‑facing SLA contracts.

Cost reality: GPUs are priced per second of active compute. A request that meets TTFT but stalls on token generation still burns GPU cycles, reducing goodput while inflating cost. Monitoring goodput helps you right‑size GPU pools.


Monitoring Architecture in Dataspanner

Below is an ASCII diagram that shows where metrics flow in a typical Dataspanner‑backed inference service.

+----------------+          +----------------+          +-------------------+
|   Client App   |  HTTPS   | Load Balancer  |  gRPC     |  Inference Service |
+----------------+----------+----------------+-----------+-------------------+
                                   |                         |
                                   v                         v
                           +----------------+      +-------------------+
                           | Queue (Redis)  |      | GPU Workers       |
                           +----------------+      | (vLLM / TRT‑LLM)  |
                                   |              |   +-------------------+
                                   v              |
                           +----------------+      |   +-------------------+
                           | Autoscaler     |      |   | Token Streamer    |
                           +----------------+      |   +-------------------+
                                                   |
                                                   v
                                           +-------------------+
                                           | Token Logger      |
                                           | (writes to Cloud  |
                                           |  Spanner "metrics")|
                                           +-------------------+

                                   +-------------------+
                                   |  Dashboard /      |
                                   |  Alerting (PromQL)|
                                   +-------------------+
  • Client App sends a request → Load Balancer distributes → Queue buffers under load → Inference Service runs the model.
  • Each token emitted is logged to a Cloud Spanner table (token_events). The table schema is deliberately narrow to keep write costs low:
CREATE TABLE token_events (
    request_id      STRING(MAX) NOT NULL,
    timestamp       TIMESTAMP NOT NULL,
    token_index     INT64 NOT NULL,   -- 0 for first token, 1… for subsequent
    token_text      STRING(MAX),     -- optional, can be omitted for cost
    is_output       BOOL NOT NULL,   -- TRUE for generated tokens, FALSE for prompts
    node_id         STRING(MAX) NOT NULL,
    queue_wait_ms   INT64,           -- optional, derived from timestamp diff
    gpu_util_pct    INT64            -- optional, from node metrics
) PRIMARY KEY (request_id, token_index);
  • A single‑query aggregates raw logs into the nine metrics. Example (BigQuery‑style SQL, works on Spanner with minor syntax tweaks):
WITH
  req_windows AS (
    SELECT
      request_id,
      MIN(timestamp) AS t_send,
      MAX(timestamp) AS t_last,
      COUNTIF(is_output) AS N_out,
      COUNTIF(NOT is_output) AS N_prompt,
      MAX(IF(is_output AND token_index = 0, timestamp, NULL)) AS t_first
    FROM token_events
    GROUP BY request_id
  ),
  latency_calc AS (
    SELECT
      request_id,
      t_send,
      t_first,
      t_last,
      N_out,
      N_prompt,
      t_first - t_send AS ttft,
      t_last - t_send AS e2e,
      t_last - t_first AS token_gen,
      IF(N_out > 1,
         (t_last - t_first) / (N_out - 1),
         NULL) AS tpot
    FROM req_windows
  )
SELECT
  COUNT(*) AS total_requests,
  AVG(ttft) AS avg_ttft,
  PERCENTILE(ttft, 50) AS p50_ttft,
  PERCENTILE(ttft, 99) AS p99_ttft,
  AVG(e2e) AS avg_e2e,
  PERCENTILE(e2e, 99) AS p99_e2e,
  AVG(token_gen) AS avg_token_gen,
  SUM(N_out) / NULLIF(SUM(e2e - t_send), 0) AS tps_out,
  COUNT(*) / NULLIF(MAX(t_last) - MIN(t_send), 0) AS rps,
  SUM(
    CASE WHEN ttft <= 200 AND tpot <= 50 AND e2e <= 2000 THEN 1 ELSE 0 END
  ) / NULLIF(COUNT(*), 0) AS goodput
FROM latency_calc;
  • Autoscaling can be tied to RPS or Goodput directly. If Goodput drops below an SLO, the scaler adds more GPU pods; if it climbs, pods are removed.

  • Cost/ops reality: Each token event row incurs a write charge in Spanner. To keep costs predictable, store only essential fields (timestamp, request_id, token_index, is_output). Omit the token text unless you need downstream analytics. Use change data capture (CDC) to stream writes to a cheaper storage layer (e.g., BigQuery) for long‑term trend analysis, while keeping the hot path in Spanner for low‑latency reads.


Practical Patterns and Common Pitfalls

Pattern 1 – “Latency‑First” SLOs for Chat UIs

  • Goal: Keep TTFT ≤ 150 ms for 95 % of requests.

  • Implementation:

    • Instrument TTFT per request in the inference service.
    • Push the metric into Spanner with a slo_type = 'ttft' tag.
    • Use a Cloud Scheduler job to compute PERCENTILE(ttft, 95) daily and alert if it breaches.
  • Trade‑off: Tight TTFT often forces smaller batch sizes, reducing GPU utilization and increasing cost per request. Balance with a “goodput” target to ensure you are not just fast but also efficient.

Pattern 2 – “Throughput‑First” for Batch Summarization

  • Goal: Achieve high TPS_out while tolerating longer E2E (e.g., up to 30 s).

  • Implementation:

    • Disable per‑token latency alerts.
    • Monitor TPS_out and RPS via the same Spanner table, but add a job_type = 'batch' column.
    • Autoscale based on TPS_out rather than latency.
  • Common mistake: Ignoring TPS_in. A batch job with huge prompts can saturate the pre‑fill stage, causing long TTFT even though output TPS looks healthy.

Pattern 3 – “Goodput‑Driven” Cost Control

  • Goal: Maintain Goodput ≥ 80 % of RPS while staying under a monthly GPU budget.
  • Implementation:
    • Define SLOs (s_ttft, s_tpot, s_e2e) in a config YAML file.
    • Deploy the config to inference pods via Kubernetes ConfigMap.
    • Expose Goodput as a Prometheus gauge; set up a Dataspanner alarm that triggers a Terraform run to scale down GPU pools when Goodput falls below threshold for >5 min.
# slo_config.yaml
slo:
  ttft_ms: 200
  tpot_ms: 50
  e2e_ms: 2000
  goodput_target: 0.80

Pitfall 1 – Confusing Mean vs. Tail Latency

  • Symptom: Dashboard shows average TTFT = 120 ms, but users complain about occasional 5‑second pauses.
  • Fix: Add P99 and P999 metrics. In Dataspanner, compute them with the PERCENTILE aggregate; store raw timestamps to avoid sampling bias.

Pitfall 2 – Using Raw TPS Without Context

  • Symptom: TPS_out spikes after a marketing campaign, but the team thinks the model is faster.
  • Fix: Always pair TPS_out with TPS_in and request length distribution. If TPS_in skyrockets while TPS_out stays flat, the bottleneck is pre‑fill, not decode.

Pitfall 3 – Over‑Instrumenting

  • Symptom: Token event logging introduces more latency and storage cost than model execution itself.
  • Fix: Sample token-level telemetry (e.g., 5–10% of production traffic) for detailed performance tracing, while logging coarse request-level metrics (TTFT, E2E, token counts) on 100% of requests.

Frequently Asked Questions

What is the most critical metric for interactive chat LLMs?

Time to First Token (TTFT) is the most critical metric for user-perceived responsiveness in conversational applications. A TTFT under 200ms feels instantaneous, whereas a high TTFT makes the UI feel frozen regardless of generation speed.

What is the difference between latency and throughput in LLM serving?

Latency measures how long a single request takes to return (TTFT and E2E latency), while throughput measures cluster capacity (Tokens Per Second or Requests Per Second). Maximizing batch size increases throughput but typically increases individual request latency.

How does P99 TTFT differ from average TTFT?

Average TTFT conceals queuing bottlenecks and memory stalls. P99 TTFT reflects the tail latency experienced by 1% of queries, exposing KV-cache thrashing, prompt prefill contention, and GPU scheduling delays.


Source context: Original announcement / coverage