LLM Inference Throughput and Latency Optimization: A Practical Guide

    This article explains how to optimize large language model inference throughput and latency under real compute constraints. It breaks perceived slowness into measurable metrics such as TTFT and TPS, covers capacity planning, tiered routing, caching, batching, observability, and resilient architecture patterns, and offers guidance on model selection and cost control for stable production service.

    1. What Subscription Pauses Reveal About Compute Supply

    A recent episode in which an AI coding tool paused new membership purchases due to compute pressure, followed by similar supply limits on comparable services, looked like a business decision on the surface. The underlying issue was insufficient effective compute on the inference side: training can be queued offline, but inference must respond in real time, and a capacity gap cannot be hidden behind “try again later.”

    This should not be read as a capability flaw in any single product. It is an engineering problem the industry faces collectively during periods of rapid demand growth. The practical takeaway for developers is to design model services as dependencies with a capacity ceiling, not as external capabilities with unlimited supply.

    2. Breaking “Slow” Into Optimizable Metrics

    What users perceive as “slow” usually mixes two independent metrics that must be measured and addressed separately:

    • TTFT (Time To First Token): the time from request submission to the first output token, which drives the instinctive sense of whether the system is stuck.
    • TPS (Tokens Per Second): the number of tokens produced per second after the first token, which determines whether reading keeps pace.
    • End-to-end latency ≈ TTFT + output length / TPS, so long-output tasks are extremely sensitive to TPS.

    Queueing delay, scheduling wait, cold starts, and the amplification effect of failed retries also matter. Many complaints about a “slow model” turn out to be bottlenecks in queueing and network paths rather than the model itself.

    3. Why “Overthinking” Slows the Overall Experience

    Some services offer high and low thinking modes to control the length of internal reasoning before generation. The benefit is fewer pointless rounds of re-derivation, but this does not change output capacity per unit time or compress queueing time. When capacity is tight, switching modes can only ease off-target answers and extremely long waits; it cannot replace capacity management.

    The correct engineering approach is tiered routing: classify tasks by complexity, send simple tasks through a low-overhead path, allow the high-overhead path only for complex tasks, and cap output length.

    1. # Example: tiered routing by task complexity to control overhead and output length
    2. def route(task):
    3. if task.complexity == "low":
    4. return {"mode": "fast", "max_tokens": 512}
    5. if task.complexity == "mid":
    6. return {"mode": "balanced", "max_tokens": 1024}
    7. return {"mode": "deep", "max_tokens": 2048}

    4. Capacity and Throughput: Getting the Most From Limited Compute

    Common ways to raise effective throughput include:

    1. Batch scheduling: merge multiple requests into a single inference pass to significantly increase output per unit of compute, at the cost of higher individual latency, which requires separate queues for interactive and offline requests.
    2. Context cache reuse: cache stable prefixes such as system prompts, codebase summaries, and long documents to cut repeated computation and directly reduce TTFT.
    3. Result caching and idempotency: reuse results for deterministic requests to avoid repeated consumption.
    4. Length governance: limit unbounded output, since output length is a linear factor in both cost and latency.
    5. Elasticity and degradation: during peaks, fall back to a smaller parameter size or shorter context, prioritizing availability.

    An illustrative capacity estimation logic:

    1. Required concurrency ≈ peak QPS × average end-to-end latency
    2. Required compute ∝ peak QPS × (input length + output length)

    These two formulas show that optimizing input and output length is as important as scaling out, and that lowering latency itself reduces the required concurrency.

    5. Observability: Measure First, Then Optimize

    No metrics, no optimization. At minimum, collect request volume, queueing time, TTFT percentiles (P50/P95/P99), TPS percentiles, timeout rate, number of degradation triggers, cache hit rate, and cost per request. Percentiles are more meaningful than averages because user complaints usually come from the long tail.

    Feed these metrics into logging and monitoring/alerting systems, set threshold alerts on P95 first-token latency and degradation rate, and form a closed loop of detect, locate, and resolve.

    6. Resilient Design at the Architecture Level

    • Multi-path redundancy: different capability tiers and deployment forms back each other up to avoid single-point dependency.
    • Asynchrony: convert long tasks to submit-and-poll or callback patterns to avoid holding connections for a long time.
    • Streaming output: deliver the first token first and keep appending, which markedly improves perceived experience.
    • Budget control: set token budgets and timeouts per user and per task to prevent individual requests from crowding out global resources.
    • Graceful failure: distinguish retryable from non-retryable errors and pair with backoff retries to avoid retry storms.

    7. Selection and Cost Decisions

    During supply constraints, selection criteria should shift from “strongest” to “good enough and stable”: use task pass rate as the core metric rather than leaderboard rankings, and run regression evaluations on a small set of real tasks, recording success rate, average latency, and cost per request. Most everyday coding and text-processing tasks can be met by a mid-size model with good context organization, reserving high-overhead capability for cases that truly need it.

    8. Conclusion

    Purchase limits on subscriptions are an external symptom of the compute supply-demand imbalance, not the end of a technical path. What developers can control: break slowness into quantifiable metrics, use tiered routing and cache reuse to cut overhead, use batching and elastic scheduling to raise throughput, and use an observability system to protect the long-tail experience. If you adopt relevant general capabilities from Baidu AI Cloud (such as a container platform to host inference services, object storage to hold context material, and logging plus monitoring/alerting for closed-loop governance), you can consolidate these methods into a service quality baseline that keeps evolving.