Production LLM Inference: Latency, Throughput, and Cost Accounting
Evaluate production LLM inference by measuring time to first token, decoding speed, sustainable throughput, and cost under consistent service-level objectives. This article explains how memory access, kernel fusion, KV cache management, parallelism, and scheduling affect performance, then outlines reproducible benchmarking and deployment checks for reliable capacity planning.
In production, the central question is not whether an inference system runs. It is whether it can meet three requirements at once: how quickly users see the first token after submitting a request, whether subsequent generation keeps pace with reading, and how many useful tokens the system can reliably produce per unit of time at an acceptable service quality.
Hardware provides compute capacity. The inference software stack determines how much of that capacity becomes useful throughput. Pricing and capacity models determine whether the result is economical. Keeping these layers separate prevents benchmark scores from becoming a substitute for operational analysis.
Define the Metrics First
Inference typically has two phases. Prefill processes the entire input at once. Its computation is generally more compute-intensive, but long contexts also place pressure on memory bandwidth and capacity through activations, the key-value (KV) cache, and intermediate tensors.
Decoding generates tokens autoregressively, one at a time. Each step requires relatively little computation but repeatedly reads the historical KV cache. The bottleneck often shifts from compute to memory access and scheduling.
At least four metrics should be evaluated together:
- Time to first token (TTFT): The time from a request entering the service until its first output token is ready to return. This includes queueing, preprocessing, prefill, and the first decoding step. For long inputs, it helps reveal the effects of fragmented prefill execution and unnecessary memory transfers.
- Decoding speed: The per-request token generation rate during steady-state output. In interactive applications, it determines whether responses feel continuous and often reflects user experience more directly than aggregate cluster throughput.
- Sustainable throughput at saturation: The number of tokens an accelerator or server can complete per second under a specified concurrency level, input-length distribution, and latency limit. Throughput without a service-level objective (SLO) is not meaningful: long queues can inflate peak throughput while making the service unusable.
- Unit economics: Whether useful output per unit of time can justify the cost of electricity, hardware depreciation, or cloud resources. Off-peak and peak pricing can differ, changing the break-even point for the same service. Comparisons must use the same request distribution, latency constraints, and accounting basis before “faster” and “cheaper” can be assessed together.
Interactive workloads are sensitive to TTFT and tail latency. Batch workloads put more emphasis on sustainable throughput and cost.
Most production traffic is mixed. A small number of very long contexts can drive prefill costs, while many short and medium requests determine whether the scheduler keeps the pipeline full. Benchmarks based only on fixed-length synthetic inputs often fail to represent production behavior.
Why Hardware Potential Often Goes Unused
Accelerator specifications usually report peak matrix multiplication performance. Inference rarely spends all its time on large matrix multiplications. Four sources of inefficiency are especially common.
Memory access. Attention, normalization, activation functions, and elementwise operations can have low arithmetic intensity. Moving data between memory and compute units may take longer than the multiply-add operations themselves. Splitting execution into smaller steps also increases kernel launches and synchronization, reducing effective utilization.
Operator fragmentation. Default framework implementations often execute mathematical expressions as separate operators, materializing intermediate results at each step. During decoding, where computation is relatively small and data movement is substantial, this turns potentially shared reads and writes into repeated global memory accesses.
Mismatched parallelism and batch sizes. Tensor, pipeline, and expert parallelism increase the model size a system can support, but they also introduce collective communication. Small batches cannot adequately amortize communication and kernel-launch overhead. Large batches increase queueing, TTFT, and tail latency. Static parallelism without request-length awareness can leave compute idle while queues grow, particularly when long and short requests share resources.
Runtime behavior. Paged KV caching, continuous batching, prefix-cache hits, preemption, and fair scheduling all affect the concurrency that the same hardware can serve. Poor scheduling can produce low utilization in monitoring dashboards while users are already experiencing timeouts.
When capable hardware performs poorly, the problem is often not insufficient peak compute. It is a software execution layer that fragments the computation graph, combined with parallelism and cache policies that do not fit the traffic.
The optimization objective should therefore be more useful tokens within the latency SLO, not simply a higher kernel microbenchmark score.
Four Reusable Software-Stack Optimizations
The following techniques are widely used in inference engineering. Prioritize them based on measured profiles rather than assuming that any one will deliver the largest improvement.
Operator Fusion
Combine adjacent small operators without cross-step dependencies into fewer kernels. Keeping intermediate results in on-chip storage or registers reduces global memory traffic and kernel-launch overhead.
Common opportunities include normalization and affine transformations, activation functions and elementwise scaling, and parts of attention preprocessing and postprocessing.
Fusion boundaries must respect numerical stability and framework maintainability. Excessively large fused kernels can increase register pressure enough to reverse the benefit. Conceptually, fusion can reduce several passes over data to a predominantly single-pass operation:
# Conceptual illustration, not a framework-specific API# Before fusion: y1 = rmsnorm(x); y2 = y1 * w; y3 = gelu(y2)# Three separate read/write stages# After fusion: y = fused_rmsnorm_mul_gelu(x, w)# Primarily a single read/write pass
Memory and KV Cache Layout
The KV cache is a major memory cost for long contexts. Paged or block-based management reduces waste from preallocation. Prefix reuse avoids repeating prefill for identical system prompts.
The layout must support two access patterns: sequential writes during prefill and strided reads across heads and layers during decoding.
Very long requests also need controls such as maximum context limits, sliding windows, or segmented summaries. Without these controls, one request can exhaust an accelerator’s cache capacity and degrade other sessions.
Parallelism and Batch Scheduling
Continuous batching allows completed requests to leave promptly and new requests to fill available slots. This avoids holding an entire batch until its longest sequence finishes. Length bucketing can reduce padding.
Tensor parallelism is appropriate when a model cannot fit on one accelerator and individual requests still require low latency. Data parallelism or additional replicas is often better suited to high request volumes with less restrictive per-request latency targets.
Overlapping communication and computation is worthwhile only when messages are large enough to amortize the overhead. Excessive partitioning during short-sequence decoding can cost more than it saves.
Runtime and Quality of Service
Separate interactive and offline traffic into queues or resource pools. Use priorities and preemption to protect TTFT.
Limit maximum generation length and request duration so that unusually long requests do not occupy batch capacity indefinitely.
Evaluate variability through P95 and P99 latency, not just averages. A service with a good average but frequent tail timeouts will still feel slow.
How to Make Comparisons Reproducible
Before comparing two inference implementations or hardware platforms, fix the following conditions.
- Keep the model configuration consistent. Use the same weights, precision—such as BF16 or a specified quantization bit width—context limit, and decoding strategy. State separately when temperature or sampling changes the execution path.
- Use representative request distributions. Draw anonymized samples from real traffic. Include at least short questions, long documents, and multi-turn requests with repeated prefixes. Report input- and output-length percentiles.
- Define latency SLOs before testing. For example, specify P99 limits for TTFT and inter-token latency, then measure the maximum stable throughput within those constraints.
- Use a consistent cost basis. Multiply the resource rate by the accelerator-hours required to achieve the measured throughput, or calculate useful tokens per accelerator-hour. Compare off-peak prices with off-peak workloads rather than using off-peak pricing to represent peak-load economics.
- Report warmup, cache hits, and cold starts separately. Strong results with a high prefix-cache hit rate do not represent performance on entirely new long documents.
An order-of-magnitude difference in theoretical compute does not automatically produce an order-of-magnitude difference in user experience.
For interactive workloads, once TTFT falls below a perceptually meaningful threshold, further reductions in average latency offer diminishing value. Unit cost then becomes more important in platform selection.
Batch workloads require a different approach: relax the SLO to the completion window the business can accept, then maximize throughput within that window.
A taxi that arrives two seconds sooner but charges substantially more illustrates the trade-off. The passenger needs to arrive on time, not win an acceleration benchmark. In inference, “on time” means returning results within the SLO, and the fare is the resource cost per unit of useful output.
Pre-Deployment Engineering Checklist
Capacity and Rollout
Estimate KV cache requirements using peak concurrency and request-length percentiles, not average input length.
Reserve headroom for the interactive resource pool so that long-document prefill does not starve decoding batches.
Use canary deployments to compare latency distributions and error rates against the previous implementation. Focus on timeouts, rejected requests, and corrupted output—not just average speed.
Observability and Output Quality
At a minimum, monitor:
- Queue waiting time
- Prefill duration
- Decoding-step duration
- KV cache occupancy
- Batch size
- Prefix-cache hit rate
- P99 latency
- Tokens produced per unit of time
Without these profiles, changes to fusion or parallelism can become subjective claims that the system “feels faster,” with no reliable basis for regression testing.
Both fusion and quantization require offline consistency checks. Verify that task-specific quality metrics, including extraction, summarization, and tool-call formatting, show no systematic regression.
Safety, Stability, and Scaling
Limit per-user concurrency and context length, and isolate exceptionally long requests.
Retain only necessary latency and length statistics in logs. Avoid writing users’ original text into general-purpose monitoring systems.
Use horizontal replica scaling to handle more requests, and choose suitable parallelism to handle longer individual requests. These are separate controls and should not be treated as one scaling knob.
Conclusion
Whether an alternative accelerator platform can support the primary production inference path depends on two factors: whether its software stack adequately handles memory access, fusion, caching, and scheduling, and whether its unit cost is competitive under the same SLO.
Peak compute specifications and absolute throughput still matter, but they describe the upper limit of supply rather than the service delivered.
Replacing fragmented operator-by-operator execution with implementations suited to decoding’s memory-access patterns, then calculating output per accelerator-hour against real traffic distributions, turns inference from a demonstration into a service that can withstand load and support defensible cost accounting.
Continue optimizing against measured profiles. Change one class of variables at a time and retain a regression test set. Reproducible engineering evidence should guide decisions—not isolated benchmark numbers.
