LLM Inference Performance Optimization: TTFT, TPS, and Compute Scheduling in Practice

    When GPU capacity is tight, LLM serving stacks respond with rate limiting, queues, and timeouts — but that vague "slowness" can be decomposed into metrics you can measure and tune. This article explains what TTFT (time to first token) and TPS (tokens per second) each capture, shows how to instrument both inside a streaming client, and covers the main levers available to developers: choosing the right reasoning intensity instead of always thinking hard, routing tasks across model tiers so scarce compute goes where it is actually needed, and applying application-side optimizations such as streaming output, multi-level caching, prompt trimming, timeouts with fallback models, concurrency control, and observability on TTFT, TPS, and error rates.

    Why Compute Pressure Reaches Developers as a Bad Experience

    Serving an LLM comes down to loading model weights into high-speed memory and then generating output token by token on accelerators with finite compute. When request volume spikes or underlying capacity falls short, providers usually protect stability through rate limiting, paused subscriptions, or queueing. To a developer, all of these mechanisms look the same from the outside: requests get slower, then time out, then fail.

    The key insight is that “slow” is not a vague subjective feeling. It decomposes into a small set of quantifiable technical metrics. Understanding those metrics is what makes sound engineering decisions possible under compute constraints — and it is the first step in turning an experience problem into an optimization problem.

    Two Yardsticks: What TTFT and TPS Actually Measure

    (1) TTFT (Time To First Token)

    The interval between sending a request and receiving the first output token. It determines how long a user waits before anything appears on screen. With streaming output, a shorter TTFT makes the interaction feel responsive. TTFT is driven mainly by queue time, prompt length (the compute cost of the prefill stage), and the service’s current load.

    (2) TPS (Tokens Per Second)

    The rate at which tokens are generated after the first one, measured per unit of time. It determines how long a complete answer takes to produce. When TPS is low, even a fast first token still leaves long-form output feeling sluggish.

    Only together do these two metrics describe the experience of a single request. Here is a rough measurement example:

    1. import time
    2. def measure_generation(client, prompt):
    3. start = time.perf_counter()
    4. first_token_time = None
    5. token_count = 0
    6. stream = client.stream_chat(prompt) # illustrative streaming call
    7. for chunk in stream:
    8. if first_token_time is None:
    9. first_token_time = time.perf_counter()
    10. token_count += 1
    11. end = time.perf_counter()
    12. ttft = first_token_time - start # time to first token
    13. decode_time = end - first_token_time # decode phase duration
    14. tps = token_count / decode_time if decode_time else 0 # generation rate
    15. return {"ttft": ttft, "tps": tps, "total": end - start}

    Once these metrics are wired into your logging and monitoring, you can pinpoint where a slowdown actually happens — queueing, prefill, or decode — instead of blaming “the service is slow.”

    Thinking Too Much Is Also a Cost: Reasoning Modes and Overthinking

    Many models offer a “high/low” reasoning intensity, or thinking/non-thinking modes. With deep thinking enabled, the model first works through a long internal chain of reasoning before producing its answer. That improves accuracy on complex reasoning tasks, but it comes with two side effects: it noticeably increases TTFT (because the model has to think first), and it consumes more tokens and more compute. When compute is tight, this overhead is especially painful.

    “Overthinking” refers to a model expanding into lengthy reasoning even for simple tasks, which produces sluggish responses and wasted resources. Ways to mitigate it include:

    • Pick the mode by complexity: use a low-intensity mode, or disable deep thinking entirely, for simple tasks;
    • Constrain it explicitly in the prompt: for example, ask for concise answers and reasoning only where necessary;
    • Run A/B evaluations: for paths with strict stability requirements, quantify the trade-off point between reasoning intensity, output quality, and latency, and decide with data rather than intuition.

    Model Tiering: Give Each Task the Right Model

    “Expensive” and “slow” tend to arrive together. A common mistake is calling the most capable, largest model for everything. A more pragmatic approach is model tiering: send lightweight, pattern-driven tasks to smaller and faster models, and only escalate to a more capable model when the task genuinely calls for complex reasoning.

    1. # Example: routing by task type
    2. def route_model(task):
    3. if task.type in ("summarize", "classify", "extract"):
    4. return "lightweight model" # prioritize speed and low cost
    5. if task.type in ("code_generation", "multi_step_reasoning"):
    6. return "reasoning-enhanced model" # requires stronger capability
    7. return "general-purpose model" # default fallback

    The core benefit of tiering is that it reserves scarce high-compute capacity for the tasks that truly need it, which raises average response speed while keeping overall cost under control.

    An Engineering-Side Latency Checklist

    Beyond the model layer, application-side optimizations also improve the experience significantly:

    • Streaming output: return tokens as they are generated over SSE or a streaming API, keeping perceived latency as low as possible;
    • Multi-level caching: reuse cached prefixes for stable system prompts, and cache results for high-frequency repeated requests, to avoid redundant computation;
    • Prompt trimming: long inputs increase prefill compute and directly push up TTFT, so remove irrelevant context;
    • Timeouts, retries, and graceful degradation: set sensible timeouts per stage, and fall back automatically to a faster or smaller model on failure;
    • Concurrency and batching: merge requests on the client side and cap concurrency so that a sudden spike does not break the pipeline;
    • Observability: use general-purpose cloud capabilities such as logging services, monitoring and alerting, and message queues (for example, products in the relevant categories from Baidu AI Cloud) to continuously collect and alert on TTFT, TPS, and error rates, so performance regressions are detectable and traceable.

    Summary

    Compute pressure is not an occasional incident; it is a long-term constraint that LLM applications have to live with. Rather than passively absorbing rate limits and latency, break the experience down into measurable signals: TTFT tells you whether the response feels responsive, TPS tells you whether generation flows smoothly, reasoning intensity tells you whether the thinking was worth the cost, and model tiering puts your resources where they matter most. Combined with engineering practices like streaming output, multi-level caching, and observability, this methodology lets developers keep delivering LLM applications that are faster, cheaper, and better under compute constraints.