Concurrency Planning and Cost Control for High-Throughput Batch Inference

    This article explains how to plan concurrency and control costs for large-scale batch inference when model quality is no longer the main differentiator. It introduces a vendor-neutral throughput model, shows how to schedule workloads across peak and off-peak windows, breaks down the real cost structure beyond cache hits, and explains why local resources and thermal limits often cap sustainable concurrency. It also covers tiered quota orchestration with idempotency and resume support, and ends with a practical action checklist.

    1. The Real Bottleneck: Time, Not Model Choice

    Some tasks are rule-driven, individually easy, and enormous in volume: batch extraction, batch validation, batch scoring, and batch rewriting. For this class of work, mainstream general-purpose LLMs already produce output quality that covers the requirement, and the differences between vendors are diluted into sample noise. Arguing over which model is smarter has limited payoff. What actually determines delivery time is a different question: how many tasks you can push through per unit of time.

    Treating time as a first-class optimization target leaves two main levers. The first is per-task efficiency: better prompts, structured output, fewer wasted round trips. The second is concurrency, letting many tasks overlap on the timeline. The second lever usually delivers order-of-magnitude gains, and it is the focus here.

    Concurrency is not “the more the better.” It is bounded by three constraints at once: server-side rate and quota policies, the input/output shape of the tasks themselves, and the physical limits of the local execution environment (memory, CPU, thermals). Ignore any one of them and you get the familiar outcome where concurrency goes up while effective throughput goes down.

    2. Modeling Multiple Lanes as Throughput

    Start with an abstraction that is independent of any specific vendor. Let t be the average time for one lane to complete one task, and N the ideal concurrency. Theoretical throughput is roughly N/t tasks per second. Real systems lose throughput in three ways:

    1. Server-side rate limiting: past a threshold, requests queue or get rejected, so effective N drops.
    2. Local resource degradation: memory pressure triggers swapping, and a saturated CPU causes scheduling jitter, so per-task t grows.
    3. Retry overhead: timeouts and throttling trigger retries, producing extra requests and extra billing.

    A more useful expression is therefore:

    1. effective throughput ≈ (N_effective / t_effective) * (1 - failure rate)

    Here N_effective is the concurrency actually achievable after rate limits and local resource limits, and t_effective is the real per-task latency under resource contention. The goal is not to push N to its maximum but to maximize the product of the three terms.

    A common mistake is watching only how many lanes were opened. If the failure rate climbs noticeably at 60 lanes and per-task latency stretches, effective throughput may fall below a stable 30 lanes. The only optimization metric that matters in engineering is tasks completed per unit of time, not lane count.

    3. Peak and Off-Peak Windows: Treat Scheduling as Shift Work

    Most hosted inference services apply different resource policies at different times of day: throttling during peak hours, more headroom overnight, and periodic promotional quotas. For batch work, this means load should be scheduled in shifts rather than spread evenly.

    A workable scheduling framework:

    • Daytime peak: use moderate, steady concurrency for latency-insensitive but high-priority tasks, accepting a stable level around 6 to 7 lanes.
    • Overnight idle window: concentrate large, deferrable jobs here, where the concurrency ceiling is usually higher.
    • Handoff buffer: leave a buffer window before and after each transition so a wave of requests does not hit the throttling switch point and fail together.

    Illustrative scheduling logic (pseudocode):

    1. def plan_batch(total_tasks, calendar):
    2. plan = []
    3. for slot in calendar: # slot holds start/end time, allowed concurrency, quota
    4. capacity = slot.concurrency * slot.duration / slot.avg_latency
    5. take = min(capacity, total_tasks)
    6. plan.append((slot.name, take))
    7. total_tasks -= take
    8. if total_tasks <= 0:
    9. break
    10. return plan

    Splitting the task queue by time-window quota tracks real server-side policy better than running a fixed concurrency to completion, and it makes completion time easier to estimate.

    4. Cost Structure: Look Past Cache Hits

    Batch inference cost has three components: cached input, uncached input, and output. A lot of attention goes to “cached input is cheaper,” but at large sample volumes there is a counterintuitive and important result: when output makes up a large share, the three components end up at similar magnitudes, and the cache discount is significantly diluted in the total bill.

    Cost estimation therefore has to go back to the structure itself. With input I and output O per task and hit rate h, per-task cost is approximately:

    1. cost ≈ h * I * p_hit + (1 - h) * I * p_miss + O * p_out

    Three practical conclusions follow:

    1. Output length is the main cost driver. Compressing output (structured fields, constrained enums, dropping explanatory prose) usually beats tuning the cache.
    2. Hit rate depends on prefix stability. Put the invariant system instructions, specs, and examples first and the changing data last to naturally improve prefix reuse.
    3. Estimate from the total bill. Run a small batch first (a few hundred tasks), record actual charges and the token distribution, then extrapolate linearly to the full volume. That is far more reliable than paper math based on unit prices.

    Note that price versions change across services, and output unit price changes have the largest effect on total cost. Budget from the currently effective price plus a measured token distribution, not from remembered prices of older versions.

    5. Local Resources Are the Hidden Ceiling

    Even when the server side allows high concurrency, the local machine gives out first. In one high-concurrency stress test, a thin laptop with 64GB of memory at 50 lanes ran at nearly 90% memory usage, with CPU fluctuating between 70% and 100% and the fan pinned at full speed. Pushing concurrency higher stretched per-task latency and effective throughput fell. The rough empirical ranges: 64GB of memory is stable at 50 lanes with a ceiling around 60; 96GB is stable at 80 lanes with a ceiling around 90.

    Another overlooked factor is the coupling between memory frequency and heat. Moving from a lower to a higher memory frequency may help slightly with a single lane, but under high concurrency heat concentrates and cooling becomes the new bottleneck, so overall throughput can drop rather than rise. In other words, sustainable local concurrency is decided by thermal design, not peak compute.

    A simplified local capacity self-check:

    1. 1. Fix the task sample (input/output lengths close to the real distribution)
    2. 2. Start at 10 lanes, add 10 per step, hold each step for 10 minutes
    3. 3. Record: effective throughput, failure rate, memory usage, CPU usage, temperature
    4. 4. Take the inflection point where effective throughput stops rising, back off one step for production
    5. 5. Verify stability over a long run and watch for slow memory leaks

    6. Tiered Orchestration Across Accounts and Quotas

    In real batch production, a single quota is often not enough. A workable approach is to tier the task queue by priority and bind each tier to a different quota source: lightweight quota for interactive development to keep responses fast; stable quota without peak/off-peak throttling to push the main workload during peak hours; and more abundant overnight quota for long-tail jobs. This uses the whole day effectively, can multiply total effective working hours, and keeps total cost under control.

    Two supporting mechanisms are needed. First, an idempotency key so retries and quota-source switches never produce duplicate results. Second, resume support that persists the identifiers of completed tasks, avoiding a full restart after a mid-run failure.

    1. def run(queue, worker, store):
    2. for task in queue:
    3. key = task.idempotency_key
    4. if store.done(key):
    5. continue
    6. try:
    7. store.save(key, worker(task))
    8. except RateLimited:
    9. queue.requeue_later(task) # requeue after backoff; completed items are not billed twice

    7. Conclusion and Action Checklist

    Once model capability is no longer the main differentiator, competitiveness in batch work comes down to concurrency engineering and cost engineering. The checklist:

    • Use tasks completed per unit of time as the only optimization metric, not lane count.
    • Split the queue by time-window quota: moderate concurrency at peak, high concurrency overnight.
    • Reverse-engineer cost from measurements, compress output length first, then improve prefix stability.
    • Measure the local inflection point in concurrency and back off one step; treat cooling as a hard constraint.
    • Build idempotency and resume support so failures under high concurrency are recoverable and never billed twice.

    With this approach, the same workload compresses from days to hours while the bill stays predictable. If you need more elastic resources and fuller observability, general-purpose capabilities such as the container platform, log service, and monitoring and alerting offered by Baidu AI Cloud can turn concurrency stress testing, task orchestration, and cost dashboards into a durable engineering system.