Chapter 55 of 60

Debugging Cost and Latency

Concepts

CHAPTER 55 β€” Debugging Cost and Latency

PART IX β€” Production Debugging and Prevention

PURPOSE

Makes spend and delay attributable per stage and request shape β€” ledger, frozen joint baseline, schedule-run budget probes β€” so optimizations ship only on joint quality+speed+spend verdicts.

CENTRAL QUESTION

How do we attribute spend and delay per pipeline stage, budget them with probes, and triage tradeoffs with evidence instead of intuition?

UNIQUE CLAIM

Only this chapter defines the per-shape cost/latency ledger (per-stage in/out tokens, stage dollars at a versioned rate card, per-stage ms, retry means with parent IDs) compared against a hashed joint baseline, with probe stability separating price drift from mix drift and prefill vs decode booked as different defects.

DEBUGGING OBJECT

Tripled $40k bill + 90s p99 with totals-only accounting: constructed ledger shows research-task shape holding 71% of growth, probes stable Β±noise Γ—3 (per-request price innocent), retry mean 1.2Γ—β†’4.8Γ— after the “quality” deploy (H2 mix-shift then H1 stage-burn in sequence; H3 masking confirmed as mechanism); single-variable retry-cap-2Γ— + later chunk-budget 12β†’6 interventions with joint predictions.

CONCEPTS INTRODUCED (only genuinely new here)

  • Ledger-by-shape + frozen joint distribution (quality + p50/p99 + per-shape spend, hash b-2026-07-01 + mix declaration) + three probe archetypes (cheap/median/research Γ—3) as H1/H2 separator + joint-ship rule (latency win with unmeasured spend = experiment, not fix)
  • Rate card as versioned changeable fact per invoice period; retry multiplier visibility (per-turn accounting blind); token-invariant (βˆ’60% tokens/task = βˆ’60% cost regardless of price)

CONCEPTS DEVELOPED / REUSED (with source chapter)

  • Consumes Ch52 segments; retry storms (Ch39/Brooker) in the cost domain; batch-invariance cost/numerics link (Ch21/40/52); probes route Ch56 live shape-burn triage

PREREQUISITES

Segmented Ch52 records + one bill/latency complaint + frozen baseline week + rate-card version + probe definitions.

LOCAL INVARIANTS

  • Book per-stage tokens/dollars/ms by shape; freeze joint baseline with hash/date/mix; probe declared shapes β‰₯3; predict all three quantities in numbers before shipping; revert on joint miss.

FAILURE MODES (this chapter’s specific ones)

  • Vendor blame without ledger; total-only accounting; baseline nostalgia; retry blindness (loops bill hourly); masked tradeoffs on single-quantity dashboards; multi-variable cost surgery; single-probe verdicts; rate-card amnesia across unlogged price changes.

DIAGNOSTIC METHOD (3-6 steps)

  1. Build per-shape per-stage ledger from Ch52 segments.
  2. Freeze joint baseline (quality + p50/p99 + spend + mix).
  3. Run declared probes Γ—3; stable probes + rising spend = mix; rising probes = stage/price drift.
  4. Ship exactly one optimization with joint numeric predictions; verify by trials.

RESEARCH-DERIVED IDEAS (papers/findings with bounds)

  • Chow et al., Mystery Machine, OSDI 2014 β€” causal request model from logs; critical path + slack + anomaly-correlated segments; per-request path variance justifies by-shape aggregation; ledger reconstructable from existing traces. Bounds: Facebook-scale web serving.
  • Gregg, Systems Performance + USE Method, 2013 (flame graphs ATC 2017) β€” measure before optimizing; per-resource Utilization/Saturation/Errors (queue = saturation, token headroom = utilization, retries/timeouts = errors); attribute where measurably spent. Bounds: general systems method, not AI-specific.
  • Token unit economics 2024–2026 (vendor docs/practitioner analyses) β€” prefill compute-bound/TTFT vs decode bandwidth-bound/inter-token; prefix/prompt caching (~90% cost/~85% latency long shared-prefix; cache-read ~10Γ— below fresh prefill, single vendor), speculative decoding (~1.5–3Γ— @ ~70% acceptance); all dated changeable facts; durable βˆ’60% invariant.
  • Leviathan, Kalman & Matias, Speculative Decoding, ICML 2023 (arXiv:2211.17192) β€” decode lever; Brooker, Backoff+Jitter, AWS 2015 β€” retry amplification (Ch39 link).
  • Dean & Barroso, The Tail at Scale, CACM 56(2):74–80, 2013 β€” at scale, rare per-component hiccups touch a large fraction of requests, so tail latency is a system property; hedged requests (duplicate after p95, cancel loser) cut the tail for ~5% extra load β€” a measured tradeoff competing with the retry budget. Bounds: web serving.
  • Yu, Jeong, Kim, Kim & Chun, Orca, OSDI 2022 (iteration-level/continuous batching); Kwon et al., vLLM/PagedAttention, SOSP 2023 (arXiv:2309.06180, paged KV cache) β€” a request’s latency and cost depend on batch composition (admit/evict at every decode step; shared GPU memory), so batch shape is a latent variable β€” the cost/latency face of Ch21/40 batch-nondeterminism. Bounds: GPU inference systems.
  • Little’s Law (L = Ξ»W) β€” queue depth should track arrival-rate Γ— service-time; if it does not, the bottleneck is elsewhere. Makes “the endpoint is saturated” checkable.

EXPERIMENT / LAB (actual lab, H-structure)

Lab 55 (PROPOSED): attribution drill. H1: one stage concentrates excess; H2: ledgers stable, mix shifted; H3: prior change moved quality vs spend/latency oppositely. Ledger by shape + three probes Γ—3 + one joint-predicted optimization verified by trials. Vendor swap/cache without attribution is not completion.

COMPANION TOOL (name + accepts/can-establish/cannot-establish)

Cost/Latency Debug Dashboard β€” accepts: segmented records, frozen baseline + mix, rate-card versions, probe defs + trials, candidate optimization + joint predictions. Can establish: which stage/mix shift explains this period’s excess and whether this optimization moves all three quantities as predicted (period + shapes + card only). Cannot establish: future prices, optimal architectures, quality beyond recorded metric; never uses totals, single percentiles, narratives, single probes, quiet.

PREVENTION ARTIFACT

Ledger (period vs baseline b-___, mix β†’, worst-shape stage burn $/ms shares, probe verdicts, quality delta) + joint optimization verdict (Q/L/S predicted vs trials: ship/revert).

READER OUTCOME (testable phrasing)

Given one endpoint with segments and one bill complaint, reader books a per-shape ledger, freezes a joint baseline hash, runs three probe shapes Γ—3 separating price from mix drift, and ships or reverts one single-variable optimization on a joint three-quantity trial verdict.

DEPENDENCIES

Ch52 segments; Ch39 retry dynamics; Ch21/40 batch-invariance; Ch54 guardrail-chain costs.

FORWARD BRIDGE

Correctness guarded and economy booked β€” both peacetime instruments; Ch56 imposes the 02:14 live-fire order (assign, freeze slice, contain, diverge, hand off) for working-hours violations.

EVIDENCE / RESEARCH REQUIREMENTS

Reader’s own ledger + baseline hash + probe trials; constructed retry-multiplier bill only, no measured runs.

ANTI-CLAIMS / LIMITS

One dashboard covers one period + shapes + pins + card version; no future-spend, no cross-mix transfer. UNKNOWN wherever segments or mix declarations missing. All percentage figures vendor-dated changeable facts.

Explain this chapter with AI

Copy this prompt into ChatGPT, Claude, Gemini, a local model, or another AI.

Apply this chapter with AI

Copy this prompt into ChatGPT, Claude, Gemini, a local model, or another AI.

Part IX β€” Production Debugging and Prevention

The invoice nobody can attribute

Chapter 54 ended with enforced checkpoints: known-bad acts refuse before they commit. Then finance forwards a $40,000 monthly inference bill β€” triple the forecast β€” alongside p99 latency at 90 seconds, and the team argues from vibes. “The model got expensive” blames the vendor; “users ask longer questions” blames the customers; “add caching” prescribes before attributing. The Chapter 52 records hold per-stage segments, but nobody has ever assembled them into a ledger. Spend and delay are debuggable quantities. The team is debugging them as weather.

OBSERVATION: total monthly spend tripled and p99 latency rose to 90s; per-request totals exist but no per-stage attribution has been assembled; quality, speed, and spend have never been segmented jointly. HYPOTHESIS H1 (stage attribution): one pipeline stage (retrieval breadth, model size, retry loops, guardrail chain) concentrates the excess. H2 (traffic mix): per-request costs are stable; the request distribution shifted toward expensive shapes. H3 (masking tradeoff): a “fix” improved one quantity by silently degrading another (quality bought with retries, latency bought with a bigger model). INFERENCE: none yet β€” H1/H2/H3 predict different ledger signatures and separate only once cost and latency are booked per stage against a baseline.

This chapter’s question: how do we attribute spend and delay per pipeline stage, budget them with probes, and triage tradeoffs with evidence instead of intuition?

Why “the model is expensive” fails first

The obvious move β€” blaming the model and swapping vendors or sizes β€” fails because price-per-token is one entry in a ledger nobody keeps. Six defects hide behind model-blame:

  1. Total-only accounting. One monthly number. Retrieval fan-out, retry multipliers, and guardrail chains hide inside it.
  2. No baseline. “Latency tripled” against no recorded distribution. Without a frozen baseline (traffic mix, pins, per-stage segments), regression is an OPINION.
  3. Retry blindness. Agent loops re-invoke the model 4–6Γ— per user turn (Part VII’s loops, now billing hourly). Per-turn accounting misses the multiplier; per-stage ledgers catch it.
  4. Context bloat. Retrieved chunks grow unbounded; input tokens quietly dominate spend while attention stays on output price. Prefill (processing the prompt) and decode (generating tokens one at a time) have different cost and latency structures β€” prefill is compute-bound and sets time-to-first-token; decode is memory-bandwidth-bound and sets inter-token latency β€” so an input-token regression and an output-token regression are different defects with different fixes (prompt-caching / retrieval budgets vs. output caps / speculative decoding). A ledger that books only “tokens” collapses the two.
  5. Masked tradeoffs. Quality “improved” after a change that tripled retries β€” or latency “improved” after a bigger, pricier model. Single-quantity dashboards celebrate while the ledger bleeds.
  6. Premature prescription. Caching, smaller models, fewer chunks β€” deployed together before attribution. Multi-variable cost surgery destroys the evidence of what actually burned.

OPINION: an undebugged AI bill is a confession that nobody owns the pipeline’s economy. Book every stage or pay every stage.

The mental model: cost/latency ledgers β€” per-stage accounts (retrieval, assembly, model, guardrail, tools, retries) booked in tokens, dollars, and milliseconds per request, summed by traffic shape, compared against a frozen baseline. Budget probes are synthetic requests of declared shapes run on schedule to separate price drift from traffic drift. Tradeoff triage reads all three quantities (quality, speed, spend) jointly β€” improving one at unmeasured cost to another is not an improvement until the ledger says so.

This is Brendan Gregg’s discipline applied to an AI pipeline: measure before optimizing, and reason about a resource in terms of Utilization, Saturation, and Errors rather than in terms of which component “feels slow” (Gregg, Systems Performance, 2013; the USE Method). The per-stage ledger is a workload characterization; the flame-graph instinct β€” attribute time to where it is actually spent, not where you assume it is spent β€” is the same instinct that stops “the model is expensive” from becoming a diagnosis.

The method: ledger, baseline, probes, tradeoff triage

Attribute spend and delay in four steps:

  1. Build the per-stage ledger. From Chapter 52 segments, book every request: per-stage input/output tokens, stage dollars at the recorded rate card (rate card version logged β€” prices change; the card is a changeable fact, attributed per invoice period), per-stage milliseconds, retry counts with parent request IDs. Aggregate by request shape (short Q&A, research task, agentic loop), not just globally.
  2. Freeze a baseline. Record the joint distribution (quality metric + p50/p99 latency + per-shape spend) under pinned environment and declared traffic mix. The baseline is MEASUREMENT with a hash and a date β€” “normal” before this chapter did not exist.
  3. Run budget probes. On schedule, replay declared probe shapes (cheap/median/expensive archetypes) through the pinned path, β‰₯3 trials each. Probes separate H1 from H2: probe costs stable while production spend rises β†’ traffic mix shifted; probes rising too β†’ stage or price drift.
  4. Triage tradeoffs jointly. Every proposed optimization states predicted effects on all three quantities with pre-written numbers. Ship only with the ledger showing the predicted joint movement across trials. A latency win with an unmeasured spend delta is an experiment, not a fix.
    flowchart TD
    L["build the per-stage ledger from Ch52 segments: tokens, dollars, ms per request, aggregated BY REQUEST SHAPE"] --> BL["freeze a joint baseline: quality metric + p50 / p99 + per-shape spend, under pinned env + declared traffic mix"]
    BL --> PB["run budget probes: cheap / median / expensive archetypes through the pinned path, >=3 trials each"]
    PB --> Q{"probes vs production"}
    Q -->|"probes stable, production spend up"| H2["H2 traffic mix shifted toward expensive shapes"]
    Q -->|"probes rising too"| H1["H1 stage or price drift β€” book which stage concentrates the excess"]
    Q -->|"a prior change moved quality and spend / latency in opposite directions"| H3["H3 masked tradeoff"]
    H1 --> OPT["propose ONE optimization with pre-written numbers for quality + latency + spend"]
    H2 --> OPT
    H3 --> OPT
    OPT --> V{"trials confirm the joint prediction on all three?"}
    V -->|yes| SHIP["ship"]
    V -->|no| REV["revert β€” a single-quantity win is an experiment, not a fix"]
  
COST/LATENCY LEDGER (per shape, per period):
shape: research-task (n=___) | baseline hash: b-___ (dated ___)
model: ___ tokens in/out, $___ (__% of shape) | retrieval: ___ chunks, $___ (__%)
retries: mean ___x (max ___) | guardrail: ___ms, $___ | tools: ___ calls, $___
p50/p99: ___/___ms (baseline ___/___) | quality: ___ (baseline ___)
probe verdict: stable / drifted at stage ___ | UNKNOWN: ___ (named)
RULE: no optimization ships on one quantity's movement. Three quantities, joint verdict.

OBSERVATION (constructed illustration, not a measured run): the research-task shape concentrates 71% of spend growth; probes are stable (same shape, same pins, same cost Β±noise across 3 trials); retry mean rose from 1.2Γ— to 4.8Γ— after the “quality improvement” deploy. UPDATED BELIEF: H2-then-H1 supported in sequence (traffic mix shifted toward research tasks AND the retry multiplier grew within that shape); H3 confirmed as mechanism (quality bought with retries, spend unmeasured). No vendor claim β€” attribution is local to this ledger and rate card.

No invoice total, no single latency percentile, no vendor price narrative, no agreement that “caching will fix it,” and no downstream quiet (“users stopped complaining about speed”) substitutes for the joint ledger with probe separation.

Example: the retry multiplier, convicted by shape

The practitioner stops debating vendors and books the stages:

# ledger-first triage: attribute, then prescribe (one variable at a time)
ledger = build_ledger(records, group_by="request_shape")  # OBSERVATION: per-stage accounts
baseline = load_baseline("b-2026-07-01")  # MEASUREMENT: frozen joint distribution
probes = run_probes(shapes=["cheap", "median", "research"], trials=3)  # H1/H2 separator
# MEASUREMENT: probes stable -> per-request price innocent; mix + multiplier guilty.
# Predictions pre-written: capping retries at 2x costs quality ___ points, saves $___.
for cap in [2]:  # single-variable intervention; quality+latency+spend read jointly
    result = apply_retry_cap(cap, trials=3)
    log(cap, result.quality_delta, result.spend_delta, result.latency_delta)

In the constructed case the retry cap at 2Γ— saves the forecast spend while quality drops within the pre-declared tolerance on the frozen eval set β€” a measured tradeoff, honestly reported, with the tolerance itself recorded as a setup choice. Context bloat gets its own intervention next (chunk budget 12β†’6, separate deploy, separate predictions), because multi-variable cost surgery is how teams save money and lose attribution in the same commit. The licensed claim covers this pipeline under this rate card and traffic mix β€” not inference economics in general.

Lab 55: attribution drill with pre-written stage predictions (proposed)

PROPOSED, not executed: no author-measured results are reported. The evidence this chapter requires is the reader’s own ledger.

Setup. Take one AI endpoint with segmented Chapter 52 records and at least one bill or latency complaint. Freeze a baseline week. The suspected stage (retrieval breadth vs. retries vs. model size vs. mix shift) is the independent variable; endpoint, pins, and rate card version are controlled.

Task.

  1. Before booking, write H1/H2/H3 with distinct predicted ledger signatures: H1: “one stage concentrates the excess (share shift within fixed mix)”; H2: “per-request ledgers stable, shape mix shifted toward expensive archetypes”; H3: “a prior change moved quality and spend/latency in opposite directions (masking).”
  2. Build the ledger by shape, run the three probe shapes β‰₯3 trials each, and record OBSERVATION (per-stage shares, probe stability) and UPDATED BELIEF.
  3. Propose exactly one optimization with joint predictions on all three quantities; verify with trials before claiming savings.
Hypothesis Predicted ledger signature FORECAST OBSERVATION (probes Γ—3) UPDATED BELIEF
H1 stage burn share concentrates at stage ___ ___ ___ live/exonerated
H2 mix shift probes stable, mix moved ___ ___ live/exonerated
H3 masking quality/spend moved oppositely ___ ___ live/exonerated

Success criterion. A per-shape ledger, a frozen baseline hash, probe results separating price drift from mix drift, and one joint-verdict optimization. A vendor swap or cache layer deployed without attribution is explicitly not completion.

Companion tool: Cost/Latency Debug Dashboard

What it accepts: segmented per-request records, the frozen baseline with its traffic-mix declaration, rate card versions, probe definitions with trial results, and candidate optimizations with joint predictions. What it performs: it books per-stage, per-shape accounts in tokens, dollars, and milliseconds; diffs the current period against the baseline jointly (quality + speed + spend); runs probe comparisons to separate drift sources; and blocks any optimization lacking pre-written three-quantity predictions with trial-backed verdicts. What it can establish: which stage or mix shift explains the excess, and whether a proposed optimization moves all three quantities as predicted β€” for the examined period, shapes, and rate card only. What it cannot establish: future price changes, optimal architectures, or quality judgments beyond the recorded metric. It never treats invoice totals, single percentiles, vendor narratives, single-run probes, or downstream quiet as attribution evidence. How its output changes your next action: stage-burn routes to a single-variable stage intervention; mix-shift routes to shape-level budgets or pricing; masking routes to joint-acceptance criteria before any “improvement” ships β€” each with pre-written numbers.

Paper form, sufficient for this chapter:

Period ___ vs baseline b-___ | shapes: ___ (mix ___ -> ___)
Worst shape ___: burn at stage ___ ($___ ___% | ___ms ___%)
Probes cheap/median/research: stable / drifted ___  Quality: ___ (baseline ___)
OPTIMIZATION: ___ predicts Q___ L___ S___ | trials: ___ VERDICT: ship / revert

Where a software implementation does not yet exist in the reader’s stack, this record is the tool. Book before blaming.

Research lineage: critical paths, resource methods, and token unit economics

The claim that spend and delay are attributable rather than atmospheric has a research spine.

End-to-end critical-path analysis. Chow et al.’s The Mystery Machine (OSDI 2014) built a causal model of a Facebook request from logs alone, then computed the critical path, quantified slack for off-critical segments, and flagged segments correlated with latency anomalies. Their headline finding transfers directly: the balance of client/server/network time on the critical path has wide variance across individual requests β€” some requests have large slack, others almost none. This is exactly why Chapter 55 aggregates the ledger by request shape and not just globally: a single p99 number averages over request populations whose critical paths differ in kind. The Mystery Machine also shows the ledger can be reconstructed from existing traces (Chapter 52 segments) without new instrumentation on every stage.

Resource-oriented methodology. Brendan Gregg’s USE Method and workload-characterization checklists (Systems Performance, 2013) formalize the “measure before optimizing” rule this chapter opens with. USE β€” for each resource, check Utilization, Saturation, Errors β€” maps onto the AI pipeline: the model endpoint’s queue depth (saturation), token-budget headroom (utilization), and retry/timeout counts (errors) are three distinct signals, and “the model is slow” usually means one specific one of them. Little’s Law (L = Ξ»W β€” mean concurrency equals arrival rate times mean residence time) turns “the endpoint is saturated” into a checkable claim: if observed queue depth does not track arrival-rate Γ— service-time, the bottleneck is somewhere else. Gregg’s flame-graph principle β€” attribute cost to where it is measurably spent β€” is the antidote to vendor-blame.

Token unit economics. Industry breakdowns of LLM serving cost (2024–2026) converge on a small number of drivers: tokens-per-task Γ— price-per-token, with prefill/decode disaggregation, prefix/prompt caching (reported ~90% cost and ~85% latency reduction on long shared-prefix prompts for one vendor; cache-read priced ~10Γ— below fresh prefill), and speculative decoding (~1.5–3Γ— decode throughput at ~70% token-acceptance) as the main levers. These are changeable facts β€” vendor-specific, dated, and re-benchmarked constantly β€” so the chapter treats the rate card as a versioned artifact and books input and output tokens separately per stage. The general lesson is durable even as the numbers move: a 60% reduction in tokens-per-task is a 60% cost reduction independent of per-token price, which is why context-budget and retry-cap interventions dominate vendor swaps.

The tail is structural, and the batch is shared. Dean and Barroso’s The Tail at Scale (CACM 2013) explains why a p99 number behaves unlike a p50: at scale, rare per-component hiccups β€” shared-resource contention, background work, queueing β€” touch a large fraction of requests, so tail latency is a property of the system, not of the slow requests alone. Their canonical mitigation, hedged requests (issue a duplicate once the first is past its p95, cancel the loser), buys a large tail reduction for roughly 5% extra load β€” a measured tradeoff, not a free lunch, and one that competes directly with the retry budget below. For LLM serving specifically, a request’s latency and cost are not independent of its neighbours: continuous, iteration-level batching admits and evicts requests at every decode step (Yu et al., 2022), and paged-KV-cache serving (Kwon et al., 2023) shares GPU memory across whatever is in flight β€” so the same request costs and stalls differently depending on batch composition. This is the cost/latency face of the batch-nondeterminism the book treats in Chapters 21 and 40, and another reason the ledger is aggregated by request shape and compared against a baseline captured under a declared traffic mix.

Retry amplification. The 1.2Γ— β†’ 4.8Γ— retry multiplier in the constructed case is the cost-domain face of the retry-storm dynamics from Chapter 39 (Brooker; exponential backoff with jitter): a change that adds a retry on borderline outputs multiplies model invocations across the whole shape, and per-turn accounting cannot see it because the multiplier lives between the turn and the stage.

Bounds: the Mystery Machine is Facebook-scale web serving; USE is a systems-performance method, not an AI-specific one; the token-economics figures are single-vendor and dated; the tail-at-scale and continuous-batching results are from web serving and GPU inference respectively. The transferable core is the method β€” critical path by request shape, resource-wise attribution, versioned rate card, separate books for prefill and decode, tail latency read as a system property, batch composition treated as a latent variable β€” not any specific percentage.

Reusable procedure: debug every bill and every timeout

  1. Book the ledger β€” per-stage tokens, dollars, milliseconds, by request shape.
  2. Freeze the baseline β€” joint distribution with hash, date, and mix declaration.
  3. Probe the path β€” declared shapes, β‰₯3 trials, price drift vs. mix drift separated.
  4. Predict jointly β€” every optimization states quality + latency + spend effects in numbers.
  5. Ship on joint verdict β€” trials confirm all three; single-quantity wins do not ship alone.

Failure modes

  • Vendor blame. “The model is expensive” without a ledger. Price is one entry; multipliers hide.
  • Total-only accounting. Monthly number, no stages. Attribution impossible by construction.
  • Baseline nostalgia. “It used to be fast” with no frozen distribution. Memory is not a baseline.
  • Retry blindness. Per-turn costs hiding per-request multipliers. Loops bill hourly.
  • Masked tradeoffs. Single-quantity dashboards celebrating ledger-bleeding “wins.”
  • Multi-variable cost surgery. Cache + smaller model + fewer chunks in one deploy. Savings unattributable.
  • Single-probe verdicts. One cheap probe declaring the system healthy. Nondeterminism and shapes require trials.
  • Rate-card amnesia. Spend compared across unlogged price changes. Version the card or misread the drift.

Limits, per contract: one dashboard covers the examined period, shapes, pins, and rate card version; it does not certify future spend, does not transfer across traffic mixes, and stays UNKNOWN where segments or mix declarations are missing.

References

  • Michael Chow, David Meisner, Jason Flinn, Daniel Peek, and Thomas Wenisch. The Mystery Machine: End-to-End Performance Analysis of Large-Scale Internet Services. Proceedings of the 11th USENIX Symposium on Operating Systems Design and Implementation (OSDI), 2014. https://www.usenix.org/conference/osdi14/technical-sessions/presentation/chow
  • Brendan Gregg. Systems Performance: Enterprise and the Cloud. Prentice Hall, 2013. (USE Method: https://www.brendangregg.com/usemethod.html; flame graphs: Visualizing Performance with Flame Graphs, USENIX ATC 2017.)
  • Benjamin Sigelman et al. Dapper, a Large-Scale Distributed Systems Tracing Infrastructure. Google Technical Report, 2010. (Cross-ref Ch 37, Ch 52 β€” trace ID as the join key for per-stage books.)
  • Jeffrey Dean and Luiz AndrΓ© Barroso. The Tail at Scale. Communications of the ACM 56(2), 2013, pp. 74–80. https://doi.org/10.1145/2408776.2408794
  • Gyeong-In Yu, Joo Seong Jeong, Geon-Woo Kim, Soojeong Kim, and Byung-Gon Chun. Orca: A Distributed Serving System for Transformer-Based Generative Models. Proceedings of the 16th USENIX Symposium on Operating Systems Design and Implementation (OSDI), 2022, pp. 521–538. https://www.usenix.org/conference/osdi22/presentation/yu
  • Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph E. Gonzalez, Hao Zhang, and Ion Stoica. Efficient Memory Management for Large Language Model Serving with PagedAttention. Proceedings of the 29th ACM Symposium on Operating Systems Principles (SOSP), 2023. https://arxiv.org/abs/2309.06180
  • Anthropic. Prompt caching documentation and pricing, 2024. https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching β€” figures dated and vendor-specific; treat as a changeable fact.
  • Yaniv Leviathan, Matan Kalman, and Yossi Matias. Fast Inference from Transformers via Speculative Decoding. Proceedings of the 40th International Conference on Machine Learning (ICML), 2023. https://arxiv.org/abs/2211.17192 (Decode-throughput lever cited in the token-economics paragraph.)
  • Marc Brooker. Exponential Backoff and Jitter. AWS Architecture Blog, 2015. (Cross-ref Ch 39 β€” retry amplification in the cost domain.)

Debugging Checklist

  • Per-stage ledger booked (tokens, dollars, ms) by request shape?
  • Baseline frozen with joint quality/latency/spend distribution + mix declaration?
  • H1/H2/H3 attribution predictions pre-written with distinct signatures?
  • Budget probes run on declared shapes with β‰₯3 trials each?
  • Price drift separated from mix drift by probe verdict?
  • Optimization predicts all three quantities in numbers before shipping?
  • Trials confirm the joint prediction (or the change reverts)?
  • Rate card version logged per period (changeable fact attributed)?
  • No totals, single percentiles, narratives, single probes, or quiet cited as attribution?

What This Chapter Established

  • Cost and latency as debuggable quantities: per-stage, per-shape ledgers, frozen baselines, and budget probes separating price drift from mix drift β€” demonstrated on the constructed retry-multiplier bill, no measured runs claimed.
  • The stage/mix/masking separation (H1/H2/H3) with the joint-verdict shipping rule.
  • Lab 55 as a proposed attribution drill the reader executes; the Cost/Latency Debug Dashboard contract (accepts/performs/can-establish/cannot-establish/next-action).
  • What was NOT proved: any general inference-economics claim, any optimal architecture, or any quality judgment beyond the recorded metric. One pipeline booked; nothing universal.
  • Position in the arc: Chapters 52–54 made failures replayable, durable, and refuzable; this chapter makes the system’s economy debuggable. Evidence now covers correctness and cost.
  • Research grounding: critical-path and slack analysis reconstructed from traces (Mystery Machine), resource-wise attribution (USE Method + Little’s Law), prefill/decode and token-unit-economics as separate books, tail latency as a system property with hedged requests as a measured-cost mitigation (Dean & Barroso), batch composition as a latent cost/latency variable under continuous batching (Orca; vLLM/PagedAttention β€” the cost face of Ch 21/40), and retry amplification as the cost face of Chapter 39’s retry storms.

Next

Correctness is guarded, spend is attributed β€” but both disciplines assume working hours and a frozen bundle. The next failure pages at 02:14 with users watching, the bundle half-frozen, and three responders improvising different procedures. Chapter 56, “Debugging in Production,” imposes live-incident discipline: what happens in which order while the system burns; what the first fifteen minutes decide is its chapter’s to establish, not this one’s.