How to Locate Performance Bottlenecks in LLM Inference Frameworks

    This guide explains a systematic approach to finding performance bottlenecks in large language model inference frameworks. It covers confirming the engine version context, building a layered metrics system across request, scheduling, operator, and system levels, tracing requests to separate queueing, prefill, and decode time, profiling operators, and running reproducible load tests. The goal is to help you move from vague "slowness" to a verified root cause using single-variable experiments.

    1. Confirm the Version Context First: Tuning Advice Has an Expiration Date

    LLM inference frameworks evolve quickly. A single engine-level rewrite can invalidate almost all prior tuning experience. Take a common open-source inference engine as an example: its next-generation engine was released as a preview in early 2025, then became the default execution path in the first quarter of that year, while the old engine was placed on a gradual deprecation plan. The real value of this timeline is not the version numbers themselves, but that it defines an “expiration date” for experience:

    • In tutorials written before the new engine became the default, advice such as manually enabling chunked prefill or hand-tuning scheduling batches mostly no longer applies to the new engine, because scheduling and batching strategies have been rebuilt and built in.
    • Once the old engine enters deprecation, patch discussions and issue conclusions based on the old implementation in the community cannot be carried over directly, or you risk arriving at a wrong root cause.

    So the first step in locating a bottleneck is always to confirm three things: the engine generation, whether the startup parameters actually took effect, and the publication date of the reference material you are relying on. From an engineering standpoint, it is a good practice to explicitly print the engine generation and key default values in the service startup logs, so you avoid pseudo-problems like “I thought I changed a parameter but it never took effect” eating up your troubleshooting time.

    2. Build a Layered Metrics System: Break “Slow” Apart

    The performance of an inference service is the result of multiple layers stacking up. Looking only at end-to-end latency in a general way will not localize the problem. It is recommended to establish at least four layers of metrics:

    1. Request layer: end-to-end latency, time to first token, time per output token, throughput (output tokens per second), timeout rate, and queueing time.
    2. Scheduling layer: waiting queue length, number of running sequences, distribution of sequences within a batch, number of preemptions and recomputations, and GPU memory block usage and fragmentation.
    3. Operator layer: time share of attention computation, matrix multiplication, normalization, sampling and post-processing, as well as kernel launch gaps.
    4. System layer: GPU memory bandwidth utilization, compute unit utilization, host-side data copies, network round trips, and serialization overhead.

    The key rule of judgment is to look at the “incremental cost”: time to first token is mainly determined by the prefill phase and is sensitive to input length; time per output token is mainly determined by the decode phase and is sensitive to concurrency scale and GPU memory bandwidth. If time to first token grows roughly linearly with input length, the bottleneck is usually in prefill compute and chunking strategy; if time per output token worsens as concurrency rises, the bottleneck is usually in GPU memory bandwidth, batch scheduling, or preemption and recomputation.

    3. Request-Level Tracing: Locate the Boundaries of Queueing, Prefill, and Decode

    In load tests and production sampling, tag each request with a unified trace identifier and record four timestamps: enqueue, prefill start, prefill completion, first token returned, and finish. From these you can compute the time share of three segments:

    1. Queueing time = prefill start time - enqueue time
    2. Prefill time = prefill completion time - prefill start time
    3. Decode time = finish time - first token returned time

    If the queueing time share is high, the problem lies in admission and scheduling, not operators; if the prefill share is high, first check the input length distribution and chunk granularity; if the decode share is high while concurrency is not high, suspect the sampling strategy, post-processing, or host-side synchronization. Doing percentile statistics (P50/P95/P99) with a logging service and monitoring alerts is far more reliable than looking at averages.

    4. Operator-Level Profiling: Distinguish “Computing Slowly” from “Waiting Long”

    First export a timeline using the framework’s built-in performance tracing capability, then answer two questions: are the compute units fully saturated, and are there large gaps in the timeline? Many gaps indicate that host-side scheduling, synchronization, or data movement has become the bottleneck; fully saturated compute means you need to optimize the compute graph and precision strategy. Common optimization directions include operator fusion, lowering numerical precision, improving the attention implementation, and increasing batch size to raise compute utilization. Note: any optimization must be premised on precision regression testing, otherwise the performance gain is not acceptable.

    5. A Reproducible Load Testing Method: Make Conclusions Hold Up

    Bottleneck localization must be reproducible. It is recommended to fix the input and output length distribution, concurrency gradient, random seed, and engine parameters, then raise concurrency step by step and plot throughput and latency curves to find the inflection point. Before the inflection point the system is not saturated; after it latency rises sharply. The inflection point marks the effective capacity ceiling of the current configuration. Only by repeating the experiment after changing a single variable can you form a causal conclusion. If you deploy on a container platform, confirm resource limits, topology, and image consistency to avoid mistaking environment differences for a framework bottleneck.

    6. Common Pitfalls and Conclusion

    Three high-frequency pitfalls: looking only at average latency, mixing experience across different engine generations, and changing multiple parameters consecutively without reproducing the issue. The proper workflow is: confirm the version context → build layered metrics → use request-level tracing to locate the phase → use operator-level profiling to confirm the root cause → validate with single-variable load testing. Logging services, monitoring alerts, and container platforms on cloud platforms such as Baidu AI Cloud can serve as support for data collection and the experimental environment, but the conclusions should still come from reproducible data of your own service.