LLM Compute Scheduling and Elastic Scaling: A Practical Guide
This guide explains why large language model services run into compute shortages after major capability upgrades and how engineering teams can respond. It covers root-cause analysis of rising per-request cost, capacity planning formulas, request tiering and priority scheduling, layered degradation policies, cost-efficiency techniques such as continuous batching and prefix caching, elastic architecture patterns, and the observability metrics needed for capacity alerts. Readers will find practical models, code and configuration examples, and a deployment checklist for keeping peak-hour service stable.
1. Framing the Problem: A Service Overload Reveals a Compute Supply-Demand Gap
A general-purpose LLM assistant that supports very long context and parallel multi-agent scheduling hit noticeable service instability within two weeks of a new release. During peak hours, clients were shown a message saying compute resources were tight and the service had automatically switched to a lightweight response mode. The official operations account replied with a joking remark: capacity was being expanded, and users were advised to try other similar services in the meantime.
Strip away the brand and the emotional reaction, and this is a classic engineering problem: compute supply on the inference side grows far more slowly than compute consumption driven by capability upgrades. The new release pushed parameter count into the trillions, adopted a sparse mixture-of-experts architecture, and supported orchestration of over a hundred parallel subtasks. Every one of those capabilities directly amplifies the compute footprint of a single request. The traffic spike from the launch, combined with higher unit cost, widened the supply-demand gap quickly.
The key point is that this is not a case of “the model isn’t good enough.” It is a case where the unit economics and capacity planning were not kept in sync. What the engineering team actually needs to answer are three questions: who is consuming compute, which consumption can be deferred or compressed, and whether scaling response speed can keep up with the traffic curve.
2. Root Cause Breakdown: What Is Eating the Compute
2.1 Structural Increase in Per-Request Cost
A sparse mixture-of-experts architecture lowers the number of activated parameters per unit, but under very long contexts, multi-turn tool calls, and parallel sub-agents, the memory and bandwidth cost of attention computation grows non-linearly with context length. The more parallel subtasks there are, the more noticeable the overhead of scheduling, context replication, and result aggregation becomes.
2.2 Traffic Shape Does Not Match Compute Shape
Conversational products are strongly time-of-day dependent: a daytime work peak and an evening entertainment peak form a bimodal curve. Compute procurement and cluster delivery, however, are measured in weeks or even months. Rigid supply meeting elastic demand inevitably produces “queuing at peak, idle spinning at trough.”
2.3 No Request Tiering
When all requests share the same resource pool and the same priority, a single batch long-document analysis job can drag interactive conversation latency down with it. Without tiering, there is no room to make trade-offs.
3. Capacity Planning: Do the Math First
The core of capacity planning is turning a vague “we don’t have enough compute” into computable metrics. At minimum, build a model like this:
Required compute ≈ Σ(QPS of request type i × average tokens per request i × compute coefficient per token) × redundancy factorRedundancy factor = 1 / (1 - target utilization) # e.g., 70% target utilization → redundancy factor ≈ 1.43
Key actions include:
- Account for compute by request type: track interactive conversation, long-form generation, batch jobs, and multi-agent orchestration separately, so averages don’t hide the long tail.
- Define utilization thresholds and queuing policy: set a safe threshold (e.g., 70%) and an alert threshold (e.g., 85%), and apply rate limiting automatically beyond them instead of indiscriminate queuing.
- Separate peak and average budgets: cover peaks with elastic resources and degradation policies, and carry the average with always-on resources. Only then is the cost structure controllable.
4. Request Tiering and Priority Scheduling
A priority queue is the highest return-on-investment change available. Four tiers as an example:
| Tier | Scenario | Latency Target | Policy |
|---|---|---|---|
| P0 | Interactive conversation, code completion | Seconds | Dedicated reserved compute; cannot be squeezed out by batch jobs |
| P1 | Standard Q&A, document summarization | A few seconds | Normal scheduling; minor queuing allowed |
| P2 | Long-document analysis, batch processing | Minutes | Run off-peak; interruptible and retryable |
| P3 | Offline evaluation, data processing | Hours | Fully asynchronous, lowest priority |
In practice, use a token bucket for admission control at the entry point, combined with a weighted queue:
# Example: admission control with prioritydef admit(req, limiter, queue):if not limiter.acquire(req.tenant_id, cost=req.estimated_cost):return reject_or_degrade(req) # rate limit or degradequeue.put(req.priority, req) # lower-priority tasks naturally move backreturn accepted
The critical piece is the ability to estimate estimated_cost: using quantile prediction based on the historical token distribution tracks real consumption more closely than a fixed quota.
5. Degradation and Switching: Turning “Unavailable” into “Available but Lighter”
Automatically switching to a lightweight mode is essentially graceful degradation. A mature layered degradation scheme typically includes:
- Model-level degradation: switch from a large sparse model to a small dense model, preserving core Q&A capability.
- Inference-parameter degradation: shorten maximum output length, compress the context window, disable parallel multi-agent orchestration.
- Feature-level degradation: temporarily turn off high-consumption capabilities (such as deep retrieval and parallel subtasks) while keeping basic conversation.
- Experience-level degradation: clearly tell users the current mode and expected recovery time, and give them a queue position.
Degradation must be controllable and rollback-able. Manage the switches centrally with a configuration center rather than hard-coding them:
degrade_policy:trigger: { queue_wait_ms: 3000, gpu_util: 0.85 }levels:- { name: L1, max_output_tokens: 1024, parallel_agents: 4 }- { name: L2, max_output_tokens: 512, parallel_agents: 1, disable_tools: true }recover: { stable_seconds: 120, step_up: one_level }
External communication matters just as much. Instead of having users retry repeatedly, give them a clear expectation and an alternative path. That reduces complaints more effectively than any PR wording.
6. Cutting Cost and Increasing Throughput: Get More Output per Unit of Compute
- Continuous batching and dynamic batch merging: combine scattered requests into batches to significantly improve GPU utilization. This is the most direct optimization on the inference side.
- Prefix cache reuse: apply prefix caching to system prompts, long documents, and code repository context; a cache hit avoids repeated prefill computation.
- Result caching and semantic caching: reuse results for frequent similar questions directly, with sensible expiration and tenant isolation.
- Quantization and distillation: use lower-precision inference within acceptable accuracy bounds, and let smaller models handle high-volume simple requests.
- Splitting long and short requests: route different length distributions to different instance pools so long requests don’t block short ones.
7. Elastic Architecture: Make Supply Keep Up with the Curve
On a general-purpose cloud environment, you can compose an elastic inference foundation from a set of capabilities: a container platform to host inference instances and scale horizontally; a message queue to buffer spikes and smooth the peak-trough difference; object storage to hold models and cache artifacts; and logging plus monitoring and alerting services to provide metrics, tracing, and capacity warnings. In these scenarios, Baidu AI Cloud is typically also built with the general combination of “container platform + message queue + monitoring and alerting” to form an elastic inference pipeline.
Scaling needs to account for cold start: loading model weights can take tens of seconds to several minutes, so you should pre-warm and scale on prediction rather than waiting until utilization is maxed out before triggering. Scheduled pre-scaling based on historical curves is often more effective than purely metric-triggered reactive scaling.
8. Observability and Capacity Alerts
Core metrics that must be in place: queuing latency distribution (P50/P95/P99), average token consumption per request, cache hit rate, average batch size, GPU utilization and memory utilization, and the number of degradation triggers plus recovery duration.
Among these, “number of degradation triggers” is the most easily overlooked yet most valuable signal: it reflects both insufficient capacity and whether the degradation policy itself is reasonable. Set tiered alerts for each metric, and make capacity review part of the release process — before a new model goes live, capacity load testing and cost estimation must be completed first.
9. Implementation Checklist
- Establish per-request-type compute accounting and utilization thresholds.
- Roll out priority queues and entry-point rate limiting.
- Configure multi-level degradation policies with one-click rollback.
- Enable continuous batching, prefix caching, and semantic caching.
- Build predictive pre-scaling and pre-warming mechanisms.
- Complete dashboards for queuing latency and degradation counts.
- Make capacity load testing a release gate.
Compute tightness is an inevitable phenomenon during a phase of rapid capability iteration. The real dividing line is whether you have the combined toolkit of tiering, degradation, caching, and elasticity. Get those four solid, and peak-hour service instability turns from an “outage incident” into an “expected lightweight mode.”
