LLM Batch Inference: Concurrency and Cost Optimization in Practice
This article explains how to optimize large language model (LLM) batch inference by focusing on effective throughput, time-based scheduling, and output cost control. It covers why concurrency is limited by local resources rather than server-side quotas, how to probe real concurrency limits with headroom, how peak and off-peak pricing can be used to schedule deferrable workloads, why output tokens are usually the dominant cost, and how tiered concurrency strategies balance delivery speed against total spend without sacrificing quality.
1. Reframing the Problem: When Model Capability Levels Out, Throughput Becomes the Focus
For tasks such as batch text processing, rule validation, and structured extraction, the logic is clear and the evaluation criteria are well defined, so the demand on a model’s upper-bound capability is not high. Once the inference quality of mainstream general-purpose LLMs crosses the usability threshold, comparing which model is “smarter” has little impact on the overall delivery timeline. What really determines delivery speed is how many tasks can be advanced per unit of time, in other words, effective concurrent throughput.
As a result, engineering evaluation should shift from “single-response quality” to three measurable dimensions:
- Average time per task (including queuing and retries);
- The number of concurrent paths that can be stably sustained;
- Total cost per task (the weighted result after pricing input, output, and cache hits separately).
Together, these three determine total working time and total spend, while model leaderboard scores affect only a small part of the picture.
2. Concurrency Is Not a Nominal Value, but a Function of Local Resources
A common misconception is treating the maximum concurrency allowed by the server as the concurrency you can actually reach. The real bottleneck is often on the client side. In batch inference scenarios, every in-flight request must retain context, pending results to be written, and connection buffers locally, so memory and file handle consumption grow linearly with concurrency.
Illustrative resource estimation and concurrency limit probing logic:
import timefrom concurrent.futures import ThreadPoolExecutordef probe(max_workers, sample=200):start = time.time()ok = 0with ThreadPoolExecutor(max_workers=max_workers) as pool:futures = [pool.submit(handle_one, i) for i in range(sample)]for f in futures:try:f.result()ok += 1except Exception:pass # rate limited or timed out, counted as failureelapsed = time.time() - startreturn ok / elapsed # effective throughput = successes / elapsed time
A typical pattern in practice is that memory usage hits the ceiling before CPU is fully saturated, becoming the real limit. When memory usage approaches 90%, CPU stays at high utilization for long periods, and cooling fans run at full speed continuously, adding more concurrency will actually reduce effective throughput due to paging and frequency throttling. A common practice is to take 80% of the “maximum runnable concurrency” as the production configuration, leaving headroom for retries and bursts.
In addition, raising memory frequency does not necessarily make things faster: higher frequency produces more heat, and once throttling kicks in, it lowers the overall rate instead. Stability takes priority over peak performance.
3. Peak and Off-Peak Pricing with Time-Based Scheduling: Spreading Work Across a Cheaper Timeline
Many platforms use time-based differential pricing for inference services, with significantly lower unit prices at night than during the day, sometimes combined with limited-time discounts. For deferrable batch tasks, this means scheduling can push costs very low.
A practical scheduling strategy is “steady by day, burst by night”:
- When concurrency is limited during the day, use moderate concurrency to keep critical paths running and preserve the interactive experience;
- At night, open up concurrency and clear the backlog in a concentrated way;
- Set separate concurrency limits and timeout thresholds for different time windows to avoid an avalanche caused by daytime rate limiting.
Pseudocode example:
def plan(now, backlog):if now.hour in NIGHT_HOURS:return {"workers": 10, "mode": "drain"} # high concurrency at night to clear backlogreturn {"workers": 6, "mode": "steady"} # steady run under daytime rate limits
It is worth emphasizing that specific quotas, discounts, and rate limit rules should be based on what the service provider currently publishes. Architecturally, do not treat any promotional period as a long-term assumption, and always keep a switchable backup channel.
4. Correcting Cost Assumptions: Output Is the Main Cost Driver
Observing the bill across larger sample sizes reveals that the unit price gap among cached input, uncached input, and output is often obscured by the “cache hit” discussion. In fact, output unit price is usually the highest, and the output volume of batch generation tasks is often far larger than the input volume. If you only optimize cache hit rate while ignoring output length control, total cost will remain high.
Actionable cost reduction measures, ordered by payoff:
- Compress output: use enum values, short JSON key names, and limited fields instead of long-sentence explanations;
- Stable prefix: place unchanged system instructions and examples at the front to improve prefix cache reuse probability;
- Batch merging: combine multiple independent small tasks into a single request to amortize fixed overhead;
- Tiered routing: send simple rule-based tasks to a lightweight model, and escalate only complex samples.
5. The Cost Boundary of Extreme Concurrency
The connection scale allowed by the server is usually far larger than what can be handled locally. In theory, pushing concurrency very high allows the same workload to finish in a very short time, but total spend does not decrease as a result—the unit price stays the same, and you are simply trading time for money. When daily consumption reaches the level of four-digit amounts in RMB, it is worth re-evaluating whether trading cash for time is worthwhile.
A more rational approach is to tier workloads:
- Urgent delivery: short-term high concurrency, accepting high cost;
- Regular batch processing: moderate concurrency at night, optimal cost;
- Offline-capable tasks: off-peak queuing, lowest cost.
6. Conclusion
At a stage where model capabilities are generally sufficient, the engineering focus for batch tasks should be on three things: effective throughput, time-based scheduling, and output cost control. First measure the real local resource ceiling and leave headroom, then use peak and off-peak strategies to smooth out the workload, and finally reduce unit cost through output compression and prefix reuse. This brings down both total time and total spend without sacrificing quality.
