LLM Inference Optimization: The Trilemma of Throughput, Latency, and Cost
Large language model (LLM) inference sits at the intersection of three competing goals—capability, latency, and cost—that continuously pull against one another. This article explains how to evaluate an online inference service across three coupled metrics: time to first token (TTFT), generation throughput (TPS), and total token consumption. It examines the architecture and infrastructure behind real performance gains, the hidden cost of reasoning ("thinking") tokens in reasoning models, and why a tiered model matrix with routing and fallback often beats betting on a single model. It also includes a minimal streaming-benchmark example and practical advice on load testing, budgeting for thinking tokens, and building observability. The takeaway is to treat capability, speed, and cost as one system of equations to solve rather than as isolated choices.
Once large model services move into large-scale production, teams care less about “how powerful the model is” and more about “whether it can complete business tasks reliably and fast enough within an acceptable cost.” Capability, speed, and cost form an interlocking triangle: more capable models typically come with higher inference overhead, while lightweight models built for low latency and high throughput may struggle on complex tasks. When a high-performance tier is replaced or retired because compute costs are too high, users naturally migrate to a more economical version—a market-level reflection of what you might call “inference economics.”
Start With the Three Core Metrics
Any evaluation of an online inference service comes down to three groups of metrics:
- Time To First Token (TTFT): The time from sending a request to receiving the first token. It directly shapes the subjective sense of “how fast the response feels” and matters most for interactive chat, code completion, and similar scenarios.
- Generation Throughput (TPS, Tokens Per Second): After the first token is returned, how many tokens the model keeps producing per unit of time. It determines the smoothness of long-form generation and streaming output.
- Total Token Cost: The full amount of tokens consumed by a task from input to output, which maps directly to the bill.
Many discussions fixate on just one of these and overlook how tightly they are coupled. A model can be “fast” (low TTFT, high TPS) yet still rack up a large bill by emitting a huge number of intermediate tokens. Evaluating an inference service therefore requires looking at all three together.
What Drives Performance Gains: Architecture and Infrastructure
When a tier can simultaneously deliver sub-second first-token latency and throughput of hundreds of tokens per second, the result usually isn’t a single-point tweak but a systemic rebuild of the inference architecture and infrastructure. Common focus areas include:
- Attention and memory optimization: More efficient KV cache management and paged memory scheduling sharply reduce memory fragmentation and redundant computation;
- Request batching and scheduling: Continuous batching lets different requests be dynamically combined into the same batch, pushing compute utilization toward its ceiling;
- Quantization and operator optimization: Trading throughput for accuracy in a controlled way, using lower-precision computation and fused operators;
- Parallelism and deployment strategy: Tensor parallelism, pipeline parallelism, and sensible instance placement determine a cluster’s overall capacity ceiling.
This point matters: when the underlying architecture is a generation ahead, the cost-effectiveness of a model with the same capability tier changes qualitatively, whereas a model built on older architecture may still cost more per unit even after a price cut. This is the real technical driver behind “the new version replaces the old version.”
The Hidden Cost of “Overthinking”
Reasoning models are one of the current trends: before giving a final answer, they first generate an internal “thinking” process (reasoning / thinking). This thinking improves accuracy on complex reasoning, math, and code tasks, but it also introduces a frequently underestimated problem—the thinking process itself consumes a large number of tokens.
This leads to a counterintuitive phenomenon:
- Even with fast first tokens and fast generation (low TTFT, high TPS), the “fast” experience cannot offset the growth in total volume;
- The tokens actually billed for each task may be considerably more than expected;
- For high-volume scenarios like batch processing and large-scale automated calls, thinking tokens significantly raise the overall cost.
Put differently, speed solves “how long you wait,” while total token volume determines “how big the bill is,” and the two cannot substitute for each other. Controlling thinking length—for example, through reasoning-budget constraints or explicit output-format requirements—is often a key part of cost optimization.
Model Tiering: Use a Matrix, Not a Single Model
The rational approach is not to bet on a single model but to build a tiered capability matrix:
- Lightweight, fast tier: For high-concurrency, low-complexity, real-time scenarios (such as chat, retrieval-augmented QA, and formatted extraction), prioritizing low latency and high throughput;
- Heavyweight, capable tier: For complex tasks that need deep reasoning (such as multi-step reasoning and complex code generation), prioritizing the capability ceiling;
- Routing and fallback strategy: A front-end scheduler assesses request difficulty, sending simple requests to the lightweight tier and escalating only complex requests to the heavyweight tier.
Below is a minimal example for evaluating streaming inference performance and quantifying cost (the interface is generic in form; refer to your platform’s SDK for the actual API):
import timedef benchmark_stream(client, prompt: str):start = time.perf_counter()first_token_time = Noneoutput_tokens = 0# Send the request in streaming modestream = client.chat.completions.create(model="<your-model-id>",messages=[{"role": "user", "content": prompt}],stream=True,)for chunk in stream:delta = chunk.choices[0].delta.content or ""if delta and first_token_time is None:first_token_time = time.perf_counter() # Record the first-token timestampoutput_tokens += len(delta) # Approximate tokens by characters; use the official tokenizer in productionend = time.perf_counter()ttft_ms = (first_token_time - start) * 1000 if first_token_time else float("inf")gen_time = end - first_token_time if first_token_time else 0tps = output_tokens / gen_time if gen_time > 0 else 0return {"ttft_ms": round(ttft_ms, 1), # Time to first token"tps": round(tps, 1), # Generation throughput"output_tokens": output_tokens, # Output token count (for cost estimation)}
Note that the token count in this example is approximated by characters and is meant only for quick validation. In production, use the official tokenizer for the model in question to count exactly, and also include the tokens of the input prompt, in order to arrive at an accurate cost.
Practical Recommendations
- Load test with your real business distribution: Don’t rely only on the peak numbers a vendor advertises. Use request lengths, concurrency levels, and task types close to production to measure TTFT/TPS and total cost.
- Budget for thinking tokens: For reasoning models, explicitly constrain thinking depth or switch to a non-reasoning version, so that “simple tasks don’t overthink.”
- Build tiering and fallback: Let cost and capability scale elastically with task difficulty rather than applying a one-size-fits-all approach.
- Keep it observable: Connect logging services, monitoring alerts, and metrics dashboards, and continuously track TTFT, TPS, token consumption, and failure rate as core SLOs; for cloud deployments, you can also rely on general-purpose infrastructure such as container platforms and object storage to handle scaling and data retention.
In large model engineering, choosing a model tier is only the starting point. What really decides success is whether you can establish clear measurement, trade-offs, and scheduling mechanisms across capability, speed, and cost. Treating these three as a system of simultaneous equations to solve—rather than as separate, isolated options—is the way to a sustainable inference service design.
