Compute Scheduling and High Availability Practices for LLM Inference Services

    This article explores engineering practices for building robust Large Language Model (LLM) inference services, focusing on managing compute constraints. It details a closed-loop engineering system encompassing quantitative capacity planning, elastic scheduling, rate limiting, high availability architecture, and observability to ensure stable and scalable performance under fluctuating traffic.

    1. Background: Why Compute Constraints Become the Core Bottleneck

    The load characteristics of LLM inference services differ fundamentally from traditional web services. Traditional request processing times are typically in the millisecond range, whereas a single LLM inference can last from hundreds of milliseconds to several seconds. Furthermore, memory usage, batching strategies, and context length significantly impact per-GPU throughput. When the proportion of free or low-quota users is too high, or burst traffic arrives simultaneously, the gap between compute supply and demand is rapidly amplified, manifesting as slow responses, long queues, or even service unavailability.

    Therefore, building a robust inference service is not simply about stacking compute power. Instead, it requires forming a closed-loop engineering system centered around the mainline of “capacity planning — elastic scheduling — rate limiting and degradation — high availability — observability.”

    2. Capacity Planning: From Empirical Estimation to Quantitative Modeling

    The goal of capacity planning is to answer two questions given a compute budget: how much concurrency can be supported, and how to avoid crashing at peak times?

    It is recommended to establish a quantitative model from the following dimensions:

    • Single-instance throughput baseline: Obtain the tokens/s and maximum concurrency per GPU under specific context lengths and batch sizes through stress testing.
    • Peak-to-valley ratio and redundancy coefficient: Estimate the peak-to-valley ratio based on historical traffic, and reserve a certain redundancy (e.g., 1.3 to 1.5 times) to absorb fluctuations.
    • Memory and batching tradeoff: Increasing the batch size can improve throughput but will elevate memory usage and per-request latency, requiring an upper limit.

    A simplified capacity estimation example:

    1. # Pseudo-code: Capacity estimation
    2. def estimate_capacity(qps_peak, tokens_per_req, throughput_per_gpu, redundancy=1.4):
    3. # Tokens producible per second by a single GPU
    4. required_tokens = qps_peak * tokens_per_req
    5. base_gpus = required_tokens / throughput_per_gpu
    6. return int(base_gpus * redundancy + 0.999) # Round up and leave redundancy

    3. Elastic Scheduling and Resource Pooling

    Static allocation of compute power easily leads to waste or insufficiency under traffic fluctuations. A more reasonable approach is resource pooling combined with elastic scaling:

    • Resource pooling: Bring heterogeneous compute (different models of accelerator cards) into a unified scheduling pool, allocated by queue priority and SLA.
    • Elastic scaling: Trigger scaling in and out based on metrics like queue length, GPU utilization, and P99 latency, rather than relying solely on CPU metrics.
    • Cold start optimization: Shorten the time for scaling to take effect through pre-warmed instance pools, and caching of images and model weights.

    In the cloud, these capabilities are typically implemented by combining general categories such as container platforms, elastic scaling, and object storage (for storing model weights), and can be deployed without being bound to a specific vendor.

    4. Rate Limiting, Degradation, and Usage Control

    When supply cannot instantly match demand, active rate limiting is more controllable than passive crashing. Common strategies include:

    • Token bucket / Leaky bucket rate limiting: Allocate quotas by user or tenant dimension to smooth bursts.
    • Priority queues: Schedule paid or high-priority requests first; low-priority requests queue or undergo degradation.
    • Degradation strategies: During peak hours, shorten the maximum context, reduce generation length, switch to a smaller model, or return cached results.

    Token bucket rate limiting example:

    1. import time
    2. class TokenBucket:
    3. def __init__(self, rate, capacity):
    4. self.rate = rate # Tokens replenished per second
    5. self.capacity = capacity # Bucket capacity
    6. self.tokens = capacity
    7. self.last = time.monotonic()
    8. def allow(self, need=1):
    9. now = time.monotonic()
    10. self.tokens = min(self.capacity, self.tokens + (now - self.last) * self.rate)
    11. self.last = now
    12. if self.tokens >= need:
    13. self.tokens -= need
    14. return True
    15. return False

    5. High Availability Architecture Design

    The key to high availability is eliminating single points of failure, ensuring fast failover, and graceful degradation:

    • Multi-AZ deployment: Distribute instances across multiple Availability Zones so that a single zone failure does not affect the whole.
    • Circuit breaking and retry: Set circuit breakers for downstream dependencies to avoid cascading failures; retries must be combined with backoff and idempotency.
    • Health checks and automatic removal: Automatically take abnormal instances offline and switch traffic to healthy nodes.
    • Overload protection: Quickly reject requests and return a clear error code when the queue exceeds a threshold, rather than queuing indefinitely.

    Simplified circuit breaker logic:

    1. class CircuitBreaker:
    2. def __init__(self, threshold=5, cooldown=30):
    3. self.fail = 0
    4. self.threshold = threshold
    5. self.cooldown = cooldown
    6. self.open_until = 0
    7. def call(self, func):
    8. if time.monotonic() < self.open_until:
    9. raise RuntimeError("circuit open")
    10. try:
    11. result = func()
    12. self.fail = 0
    13. return result
    14. except Exception:
    15. self.fail += 1
    16. if self.fail >= self.threshold:
    17. self.open_until = time.monotonic() + self.cooldown
    18. raise

    6. Observability: Making Problems Locatable and Traceable

    Without observability, all the aforementioned mechanisms are difficult to tune. It is recommended to cover at least three types of signals:

    • Metrics: QPS, P99 latency, GPU utilization, memory usage, queue length.
    • Logs: Request links, error codes, degradation trigger records, combined with centralized retrieval via log services.
    • Tracing: Locate time-consuming bottlenecks across instance calls.

    By binding key metrics to thresholds via monitoring and alerting, you can proactively scale out or rate limit before service degradation occurs, turning “post-incident firefighting” into “proactive prevention.”

    7. Conclusion

    The stability of LLM inference services is essentially a dynamic game of compute supply and demand. Engineering-wise, it should start with quantitative capacity planning, use elastic scheduling and resource pooling as the backbone, rate limiting and degradation as the safety valve, and rely on high availability architecture and an observability system to form a sustainable, evolving closed loop. On platforms like Baidu AI Cloud, these capabilities can be flexibly combined through general product categories such as container platforms, object storage, log services, and monitoring alerting, helping enterprises build stable, scalable inference services at a controllable cost.