Optimizing LLM Inference Costs Under High Concurrency: A Practical Guide

    This article explains how to optimize large language model inference costs when running multiple concurrent requests. It shows why price per million tokens is a misleading metric, how local hardware becomes the real concurrency ceiling, and how billing structure, scheduling, and prompt design affect the final bill. You will find a practical throughput model, hardware sizing guidelines, a lane-selection scheduling example, and a four-step implementation approach.

    1. The Problem: Unit Price Is No Longer the Main Variable

    For tasks such as batch text processing, structured extraction, rule validation, and bulk rewriting, model capability is often already “good enough.” What actually limits delivery speed is how many tasks you can push through per unit of time. If you only compare quotes per million tokens, you can easily reach the wrong conclusion: the channel with the lowest unit price is not necessarily the one with the shortest total runtime or the lowest total cost.

    So the evaluation metric needs to shift from “unit price” to “effective throughput,” meaning the number of results actually completed and persisted per unit of time. This metric is constrained by three factors: server-side concurrency and rate limits, local client resources, and the billing structure (whether peak/off-peak differences exist, and whether subscription quota is consumed).

    2. Higher Concurrency Is Not Always Better: Local Resources Are the Real Ceiling

    Many teams assume the concurrency limit is set by the server, but in real load tests their own machine usually becomes the bottleneck first. In one typical batch experiment, a single machine ran roughly fifty concurrent lanes for over ten hours and produced more than thirty thousand results. Memory usage stayed near ninety percent, CPU utilization fluctuated between seventy percent and full load, cooling fans ran at high speed for long stretches, and the machine entered a throttling range where throughput actually dropped.

    This can be abstracted into an empirical model:

    1. effective throughput ≈ min(server-allowed concurrency, locally sustainable concurrency) × per-lane success rate × (1 - retry rate)

    Here, “locally sustainable concurrency” is mainly determined by memory capacity and memory bandwidth. The rough empirical ranges are: 64GB of memory suits around fifty lanes (upper limit about sixty), and 96GB can support around eighty lanes (upper limit about ninety). It is worth noting that raising memory frequency from a lower tier to a higher one may help in single-lane scenarios, but under high concurrency the extra heat and power draw reduce stability, and overall throughput may drop rather than rise.

    Practical recommendations:

    • Run stepped load tests first (10/20/40/60 lanes) and record the throughput inflection point and the error-rate inflection point, instead of maxing out immediately;
    • Make retries, rate-limit backoff, and result persistence asynchronous queues so a single blocking point does not drag down the whole pipeline;
    • Monitor memory, CPU temperature, and throttling events, and define “sustainable concurrency” as the concurrency level that runs for a long time without throttling.

    3. Billing Structure Matters More Than Unit Price

    Batch task cost has three components: input that hits the cache, input that misses the cache, and output. In large-sample experiments, a counterintuitive but common finding is that the three amounts can be of the same order of magnitude. That means over-optimizing cache hit rate yields limited gains, while the output side is where the real cost lies. If a channel’s output unit price is clearly high, the total bill will still be more expensive even with a cache discount on the input side.

    This leads to two general strategies:

    1. Peak/off-peak routing. Put deferrable batch jobs in nighttime or off-peak windows, and put interactive, latency-sensitive requests in peak windows, trading scheduling for price.
    2. Quota first. If you already hold a recurring subscription quota, consume that quota first and reserve pay-as-you-go channels for sudden spikes and very long tasks.

    An actionable scheduling skeleton looks like this:

    1. def choose_lane(task, hour, quota_left):
    2. # Interactive tasks prefer the low-latency lane; batch jobs prefer the cheap nighttime lane
    3. if task.latency_sensitive:
    4. return "lane_a"
    5. if quota_left > 0:
    6. return "lane_quota"
    7. return "lane_b" if 1 <= hour < 8 else "lane_a"

    4. Combining Subscription Quota With Pay-as-You-Go

    A fairly safe approach is to split the day into alternating windows: use a stable multi-lane channel with no peak/off-peak difference during the day to push the main workload; switch at night to a channel with looser concurrency limits and periodic discounts; then switch back to the daytime channel in the early morning. This both extends effective working hours and lets the two types of quota and the two billing structures cover for each other.

    It is worth stressing that any “limited-time offer” or “double credits at night” promotion is time-bound. Do not build a long-term cost model on short-term promotions; treat promotions as extra upside instead.

    5. Using Caching and Prompt Engineering Correctly

    Caching only makes sense when the input prefix is highly repetitive. More effective cost-reduction measures in batch scenarios are:

    • Compress prompts and remove instructions unrelated to the task;
    • Standardize the structured output format to reduce invalid output and retries caused by parsing failures;
    • Split long documents into a reusable prefix plus a variable suffix so the prefix is naturally cacheable;
    • Archive failed samples separately to avoid rerunning the whole batch and being billed twice.

    6. Conclusion

    The essence of multi-lane concurrency is using engineering to trade “time” for “cost efficiency.” In practice, follow four steps: first load-test to determine local sustainable concurrency; then schedule lanes based on peak/off-peak windows and quota; then evaluate the bill by output cost rather than cache hit rate; and finally keep some headroom for rate limiting and throttling. If you need more elastic compute and more complete supporting capabilities, you can combine general product capabilities such as Baidu AI Cloud’s container platform, object storage, message queue, and monitoring and alerting services to turn the batch pipeline into an observable, elastically scalable workflow.