Throughput Optimization and Time Cost Control for High-Concurrency Batch Inference

    As LLM capabilities converge, the bottleneck for large-scale batch inference tasks shifts from model selection to throughput and unit cost. This article explores engineering strategies to optimize wall time and expenses, covering time-based capacity planning formulas, tiered scheduling combining pay-as-you-go and subscription models, cost attribution for token usage, identifying client-side hardware bottlenecks, and best practices for building robust concurrency pools. By treating concurrency as an engineering parameter requiring rigorous capacity planning, developers can achieve significant gains in delivery efficiency.

    I. Problem Redefinition: When Capabilities Converge, Time is the Bottleneck

    In tasks such as batch data processing, rule extraction, format conversion, and batch tagging, the input structure is clear, the decision logic is simple, and the difficulty of a single item is low, but the number of items is massive. This type of workload shares a common characteristic: it has very low sensitivity to the model’s “intelligence ceiling,” but extreme sensitivity to throughput and unit cost.

    Once the accuracy difference among mainstream inference services for these tasks falls into the single-digit percentage range, the marginal return of continuing to conduct horizontal model evaluations drops rapidly. What truly determines the delivery cycle is another variable: how many tasks can be processed per unit of time. Therefore, the discussion framework should shift from “model selection” to “capacity planning.”

    II. Formulating the Time Investment

    Let N be the total task volume, C be the effective number of concurrent paths, and T be the average end-to-end latency per request. The theoretical total wall time is:

    1. WallTime ≈ N / C × T

    This formula reveals three intervention points:

    1. Increase C: Multi-path concurrency is the most direct method to compress total time, yielding almost linear returns (within the server’s non-throttling range).
    2. Reduce T: Achieved through shorter outputs, more concise prompts, and fewer retries.
    3. Increase the time proportion of effective C: Let the high-concurrency window cover as many clock hours as possible.

    The third point is the most easily overlooked. The effective concurrency of many services is not constant but fluctuates with time periods: looser during night windows, tighter during daytime peaks. If we integrate the “daily effective concurrency” weighted by time, we get the true daily capacity:

    1. DailyCapacity = ∫ C(t) dt (Summed by hourly slices)

    A combination of an 8-hour low-concurrency window and a 14-hour high-concurrency window often yields significantly better daily capacity than a 24-hour single-path run, and is also better than cramming all tasks into the daytime peak.

    III. Tiered Scheduling: Combining Quota-Based and Pay-As-You-Go Models

    The cost side of batch inference typically involves three forms. Understanding their differences is the prerequisite for saving money:

    • Pay-as-you-go: Billed per token, usually distinguishing between “uncached input,” “cached input,” and “output” at three different price tiers. The output unit price is generally the highest.
    • Periodic subscription quota: Issued at fixed cycles, non-rollover if unused, and limited if exceeded. The unit cost is lowest when the quota is fully utilized.
    • Off-peak pricing: The same service has different unit prices at different times, with night prices significantly lower than daytime.

    The core idea of the combination strategy is to match task attributes with billing forms:

    Time Period Preferred Form Reason
    Daytime Peak Periodic subscription quota Near-zero marginal cost, and concurrency limits match medium concurrency well
    Night Valley Pay-as-you-go with off-peak discount Widest concurrency window, lowest unit price, suitable for pushing high throughput
    Quota Exhausted Pay-as-you-go fallback Prevents tasks from stalling

    In engineering, you only need to maintain a “scheduler priority table” that dynamically selects the backend based on the current clock and remaining quota. The task itself is unaware of the backend switching.

    1. def pick_backend(now, quota_left):
    2. if is_day_peak(now) and quota_left > 0:
    3. return "quota_plan", 6 # Medium concurrency, zero marginal cost
    4. if is_night_window(now):
    5. return "metered_offpeak", 10 # High concurrency, low unit price
    6. return "metered_peak", 5

    IV. Cache Hit Rate: Don’t Misplace Your Optimization Focus

    A common misconception is over-focusing on the “cached input unit price” and refactoring prompt prefixes for this purpose. The reality is: in batch tasks with large samples and long outputs, output tokens often dominate the cost, and the input side, whether cached or not, is only a secondary factor.

    The correct approach is to perform a cost attribution on your own real corpus rather than copying others’ conclusions:

    1. cost = (in_miss * p_in_miss
    2. + in_hit * p_in_hit
    3. + out * p_out)
    4. # Count the proportion of the three items, then decide the optimization direction

    If the output accounts for more than half of the total cost, the optimization focus should be on: compressing the output structure (using compact formats instead of verbose natural language), reducing explanatory text, splitting multi-turn tasks into single-turn, and using constrained output for enumerable results. The returns from these methods are usually far greater than caching prompt prefixes.

    V. The Real Bottleneck is on the Client Side

    The high concurrency limit declared by the server is often not your actual bottleneck. Taking single-machine multi-path stress testing as an example, the limiting factors usually appear in the following order:

    1. Memory capacity: Each concurrent path must maintain request context, response buffers, and parsing intermediate states, with memory usage growing almost linearly with concurrency. Empirically, 64GB-class memory hits over 85% utilization at around 50 concurrent paths, while 96GB-class can support about 80 paths.
    2. CPU and serialization overhead: JSON parsing, text post-processing, and result writing to disk can quickly push the CPU to saturation.
    3. Negative feedback from thermal and memory frequency: High-frequency memory generates more heat. Once thermal throttling is triggered, the single-request latency T actually increases, making T in N/C×T larger, which eats away part of the concurrency gains. Blindly increasing memory frequency in multi-path scenarios may be a negative optimization.
    4. Local disk I/O: When writing results at high frequency, synchronous disk writes become a hidden serialization point and should be changed to batch asynchronous writes.

    Therefore, capacity planning should leave a safety margin: use “recommended concurrency” rather than “limit concurrency” for daily configurations, reserving the limit for short bursts.

    VI. Engineering Essentials for Concurrency Pools

    Multi-path concurrency is not simply opening threads; it requires four mechanisms to ensure stability over long runs:

    • Token bucket rate limiting: The client actively throttles to avoid triggering server 429 errors and falling into a retry storm.
    • Exponential backoff + jitter: Randomizing retry intervals prevents synchronous resonance.
    • Idempotency and resume: Each task carries a stable ID. Results are written to a local queue first before batch uploading. After an interruption, only the unfinished parts are retried.
    • Observability: Report concurrency, success rate, P95 latency, and unit cost to logging and monitoring alerting services. Tune parameters using data, not feelings.
    1. async def worker(sem, limiter, task):
    2. async with sem: # Control the number of concurrent paths
    3. await limiter.acquire() # Token bucket rate limiting
    4. for attempt in range(5):
    5. try:
    6. r = await call_model(task)
    7. await sink.append(task.id, r) # Idempotent disk write
    8. return
    9. except RateLimited:
    10. await asyncio.sleep(base * 2**attempt * random.random())

    General cloud product categories such as object storage, message queues, logging services, and monitoring alerting (for example, capabilities provided as standard products on Baidu AI Cloud) are sufficient to support this “queue-compute-store-observe” skeleton without relying on any proprietary interfaces.

    VII. Conclusion

    In batch task scenarios where capabilities have converged, the optimization order should be: first quantify the time formula -> then use a combination of tiered pricing and quotas to elevate daily effective concurrency -> then use real cost attribution to decide whether to optimize input or output -> finally deduce safe concurrency based on client memory and thermal constraints. The returns from horizontal model evaluation are now minimal, while the returns from scheduling strategies and capacity planning are on the order of multiples. The most important cognitive shift for this type of workload is treating concurrency as an engineering parameter requiring capacity planning, rather than a configuration item that can be infinitely increased.