AI-Generated Inference Engine: Testing TTFT Under 16 Concurrent Requests

    This article evaluates the performance of an AI-generated LLM inference engine by comparing its Time To First Token (TTFT) and P90 latency against an industry-mature open-source solution under 16 concurrent requests. It covers the testing methodology, metric definitions, potential causes of long-tail latency, and key considerations for production deployment.

    1. Background: Can AI Automatically Write Inference Engines?

    An LLM inference engine must handle four tasks: receiving inference requests, managing VRAM and compute resources, scheduling the GPU to run the model, and returning generated tokens to the client. The industry has established mature architectures, including request queues, batch scheduling, KV Cache management, and streaming output.

    These clear module boundaries make it an ideal task for AI coding tools. Researchers can provide clear requirements and let the tool generate a complete engine covering request intake, GPU scheduling, model execution, and response return.

    However, working code does not guarantee good performance. Therefore, the focus of the study is empirical testing: how much do the numbers differ between two engines under the same hardware, model, and batch of requests?

    2. Defining Metrics: First Token Latency and P90

    In streaming inference services, the most direct user experience metric is Time To First Token (TTFT)—the time from sending a request to receiving the first token. It determines whether users feel the service is “frozen.”

    Relying solely on averages is problematic. Most requests may be fast while a few are slow, meaning the average is dragged down by the fast ones, masking long-tail issues. P90, representing the time within which 90% of requests begin returning content, better reflects the upper limit of most users’ real experience. P99 focuses on the slowest segment of users.

    The calculation method for percentiles needs clarification. Here, we use the nearest-rank method:

    1. import math
    2. def p90_nearest_rank(latencies):
    3. """latencies: list of all request TTFTs in seconds"""
    4. sorted_lat = sorted(latencies)
    5. n = len(sorted_lat)
    6. rank = math.ceil(0.9 * n) # Which sample (1-based index)
    7. return sorted_lat[rank - 1]

    For example, with 10 requests, the nearest-rank method takes the 9th smallest value. If you use int(n * 0.9) as the index, it would take the 10th value (the maximum) when n=10, resulting in a higher value. numpy.percentile defaults to linear interpolation, which may differ from the nearest-rank method. When reporting percentiles, the method used should be explicitly stated.

    3. Test Conditions: Unclear Conditions Make Results Hard to Reproduce

    The same numbers mean completely different things under different conditions. When conducting stress tests, it is recommended to record at least the following:

    • Hardware: GPU model, count, interconnect topology, VRAM size, driver, and CUDA version
    • Model: Name, version, precision (e.g., FP16, INT8)
    • Request distribution: Distribution of input and output lengths, not just averages
    • Concurrency method: Whether 16 concurrent requests are initiated simultaneously, replayed by arrival time, or queued
    • Sampling parameters: temperature, top_p, max_tokens, etc.
    • Warmup and repetition: Whether warmup was performed, how many rounds per group, and how many requests per round
    • Measurement tools: When the client starts timing, and which event of the first token serves as the endpoint

    In the original study, both engines ran on identical hardware and request sequences, adhering to the basic principle of controlling variables. However, to make the comparison credible, the specific projects, versions, and configurations of the compared engines must be public, clarifying whether default or tuned parameters were used. Otherwise, readers cannot determine if the 25x difference stems from engine implementation or configuration discrepancies.

    Replaying real session logs also involves privacy and compliance issues. Session content often contains code, business information, or even credentials. Authorization must be obtained before use, and the data should be desensitized by removing sensitive fields before stress testing.

    4. How to Interpret the Results

    The original test provided the following numbers:

    Engine Version P90 TTFT
    Industry-mature open-source solution (v0.5.20) ~12.029s
    AI-generated engine ~0.478s

    The difference is roughly 25x. Based on these numbers, in an interactive programming scenario, one engine starts returning content almost immediately, while the other takes over ten seconds.

    When reading these numbers, three things must be noted. First, the raw sample size and percentile calculation scripts should be public; otherwise, only a point estimate is visible. Second, single-test results fluctuate with load, time, and cache state, so multiple repetitions should be conducted to show the fluctuation range. Third, TTFT is only one metric; it does not indicate that throughput, stability, or feature completeness are equally superior.

    5. Why the Long-Tail Latency Differs So Much

    Mature engines often merge multiple requests into large batches to improve throughput. New requests must wait for the current batch to finish before entering computation, increasing queue time. Scheduling strategies optimized for latency allow new requests to join computation earlier.

    The prefill phase is the primary overhead for TTFT. If a very long prompt occupies compute resources, subsequent short requests can only wait. Chunked prefill can split long prompts and execute them alternately with other requests, reducing blocking. The paging management and VRAM allocation method of the KV Cache also affect whether requests can obtain enough space promptly.

    Lock contention, unnecessary serialization, and synchronization waits on the request path have small individual overheads, but they are amplified under 16-way concurrency, becoming sources of long-tail latency.

    When troubleshooting, follow these steps:

    1. Record the queue time, prefill time, and TTFT for each request to determine where the latency is primarily spent.
    2. Adjust the maximum number of concurrent sequences (e.g., max_num_seqs) and batch size, observe P90 changes, and find the balance between throughput and latency.
    3. Enable or disable chunked prefill and compare results under mixed long-prompt loads.
    4. Check the KV Cache block size and VRAM usage to confirm if frequent swapping or allocation waiting is occurring.
    5. Use profiling tools to inspect locks and synchronization points on the request path, verifying one by one whether they truly constitute bottlenecks.

    Change only one variable per step and retain the complete data before and after the change, so performance changes can be attributed to specific causes.

    6. Beyond Metrics: What Else is Needed for Production

    A drop in P90 does not mean the service is ready to go live. Production environments require evaluating at least the following:

    • Throughput: How many tokens can be processed per unit time, and whether it drops significantly under high concurrency
    • Stability: Whether memory leaks exist during long-term operation, and whether recovery is possible after errors
    • Feature completeness: Capabilities like multi-model, multi-GPU, quantization, structured output, and tool calling
    • Security: Request authentication, input validation, and whether user content is leaked in logs
    • Monitoring and alerting: Whether metrics like TTFT, TPOT, queue length, and GPU utilization can be observed
    • Maintenance cost: Who reads, fixes, and upgrades the AI-generated code, and whether issues can be quickly located

    7. Conclusion

    This experiment shows that, given clearly defined requirements and evaluation criteria, AI tools can generate an inference engine with excellent TTFT performance. It demonstrates a viable R&D path: define clear goals, measure with real workloads, and iterate accordingly.

    However, this result comes from only one set of test conditions. It cannot be directly extrapolated to suggest that AI is universally capable of writing system-level software, nor does it prove that the generated engine is equally excellent in throughput, stability, and maintenance. When adopting this methodology, readers should first clarify their own test conditions, metric definitions, and production requirements before judging whether the conclusions apply.