LLM Batch Inference: Concurrency Scheduling and Cost Optimization in Practice
This article breaks down how to handle high-volume, low-complexity LLM workloads such as batch data cleaning, structured extraction, and rule validation. It explains why effective concurrency and billing structure matter more than raw model quality, and walks through a four-layer pipeline design, adaptive concurrency control, off-peak scheduling, and cost governance tactics including output compression, result caching, and budget circuit breakers.
1. Background: Model Capability Is No Longer the Bottleneck
By 2026, an increasingly clear engineering reality is that for tasks with well-defined rules, deterministic steps, and simple per-step decisions but massive total volume—batch data cleaning, structured extraction, format conversion, rule validation, batch scoring—mainstream LLM services have become highly homogeneous in output quality. Debating “which model is smarter” during selection yields very little. What actually determines delivery timelines and the final bill are two other things: effective concurrency and billing structure.
This article refers to this class of tasks as “workhorse workloads”: each request is simple, the total count reaches the hundreds of thousands, per-request latency is not critical, but overall throughput and total cost are extremely sensitive. Below is a reusable engineering methodology for these workloads.
2. Evaluation Dimensions: Look Beyond Unit Price
2.1 Throughput: Effective Lanes, Not Theoretical Concurrency
“How many lanes can I open” is not the same as “how many threads the client can spawn.” Effective lanes are determined by server-side quotas, rate limits, and queueing policies, and typically exhibit three characteristics:
- Time-of-day variation: Available concurrency at night often differs from daytime; peak hours see gradual throttling.
- Progressive degradation: Past a threshold, requests are not hard-failed—queues lengthen and lane count slowly drops.
- Mutual contention: When multiple models under the same account share a quota, their peaks interfere with each other.
The right metric is therefore “tasks completed per unit time,” not the instantaneous concurrency ceiling.
2.2 Latency: Separate Per-Request Latency from Total Makespan
What batch jobs actually care about is makespan. The approximate relationship is:
makespan ≈ total tasks / (effective lanes × per-lane success rate) × average per-request time
Increasing lane count and reducing retry rates is more effective than optimizing single-request latency.
2.3 Cost: Break Down the Billing Items
Common billing items include uncached input, cache-hit input, output, and peak/off-peak differentials on some services. A counterintuitive but important finding: at large sample sizes, the consumption ratio of the three token types can approach 1
1. This means over-optimizing cache hit rate does little for the total bill, while changes to the output unit price have the largest impact.
3. Architecture: A Multi-Lane Pipeline
3.1 Basic Structure
Split the system into four layers: task sharding, concurrency control, call execution, and result persistence.
import asyncio, randomsem = asyncio.Semaphore(6) # effective lanes, tune based on measurementretry_max = 3async def call_one(item, client):async with sem:for i in range(retry_max):try:return await client.generate(item.prompt)except Exception:# exponential backoff + jitter to avoid retry stormsawait asyncio.sleep(min(2 ** i, 8) + random.random())return {"error": True, "input": item}async def run(items, client):results = await asyncio.gather(*(call_one(x, client) for x in items))return results
3.2 Adaptive Concurrency
A fixed lane count is not optimal under peak/off-peak swings. A simple AIMD (additive increase, multiplicative decrease) controller works well: increment by one on success, halve on throttling, with upper and lower bounds.
class AdaptiveLimiter:def __init__(self, low=2, high=10):self.low, self.high = low, highself.limit = lowdef on_success(self):self.limit = min(self.high, self.limit + 1)def on_throttle(self):self.limit = max(self.low, self.limit // 2)
3.3 Reliability Essentials
- Idempotency keys: Generate a stable ID per shard so reruns produce no duplicates.
- Checkpoint resume: Append results per shard; after a crash, only backfill the missing parts.
- Separate throttling from retries: Throttling goes through backoff; business errors go straight to a dead-letter queue for manual review.
- Observability: Instrument lane count, queue time, failure rate, and token consumption separately, and wire them into alerting.
4. Scheduling: Off-Peak and Hybrid Orchestration
Off-peak scheduling combines “more abundant concurrency during valleys” with “more stable quota during peaks,” using two channels to cover the full day:
Daytime (high stability need) -> Channel A: steady ~5 lanes, no peak/off-peak differentialNighttime (high throughput need) -> Channel B: steady 8–10 lanes at night, off-peak discount
In practice, a single routing switch is enough—switch the default channel by time window and keep a manual override:
def pick_channel(hour: int) -> str:return "B" if hour >= 20 or hour < 8 else "A"
Pair this with a daily quota check: allocate the total daily token budget across channels according to their capacity, so one channel does not exhaust early and leave the night idle.
5. Cost Governance: Work Backward from the Bill
- Calibrate on a small sample first: Use a few hundred real records to measure the actual ratio of input, cache-hit input, and output, then estimate total cost from that—not from a price sheet guess.
- Compress output: Output tokens are usually the most expensive. Use enums, short schemas, and compact JSON instead of long natural language whenever possible.
- Reuse stable prefixes: Put long, fixed instructions and examples in the request prefix to raise prefix reuse odds—but do not expect it alone to turn the bill around.
- Cache and deduplicate results: Batch tasks have high repetition; content-hash-based result caching often beats input-hit optimization.
- Set a budget circuit breaker: Define an hourly spend threshold; auto-throttle and alert when exceeded to avoid an unbearable bill from one rush job.
- Watch for “seemingly cheaper” pricing: If the output unit price has not dropped in tandem, total cost may actually rise—always defer to calibration results.
6. Common Pitfalls
- Treating peak concurrency as steady-state capacity.
- Fixating on cache hit rate while ignoring the output share.
- Dense retries without backoff, which further reduces effective lanes.
- Missing idempotency and checkpoint resume, forcing a full rerun after failure.
- Estimating batch makespan from average single-request latency.
7. Conclusion
In a stage of capability homogeneity, the competitive edge in batch inference has shifted from “model quality” to “scheduling efficiency and cost structure.” A practical path: use effective lane count as the core metric and calibrate empirically; build a stable multi-lane pipeline with semaphores and adaptive backoff; fill the full-day time window with off-peak and dual-channel orchestration; and keep costs predictable through output compression, result caching, and budget circuit breakers. If you need managed task orchestration, logging, and monitoring, general-purpose cloud primitives—container platforms, message queues, object storage, and monitoring/alerting—can handle it without building the entire stack yourself.
