To optimize vLLM serving for multiple clients with varying workloads and prevent slowdowns, here are several strategies you can implement:
1. Configure Dynamic Batching Parameters
vLLM's dynamic batching is key to preventing long requests from blocking shorter ones:
# Key parameters to tune
--max-num-batched-tokens # Total tokens across all sequences in a batch
--max-num-seqs # Maximum sequences processed simultaneously
--max-model-len # Maximum sequence length allowed
For mixed workloads, use conservative values that balance throughput:
- Set
max-num-batched-tokens based on your GPU memory
- Keep
max-num-seqs moderate (16-32) to allow quick processing of short requests
2. Implement Request-Level Controls
Set different limits per client or request type:
# In your request handling layer
async def handle_request(request):
# Assign priority based on expected length
if request.estimated_tokens < 500:
priority = "high"
timeout = 30
else:
priority = "normal"
timeout = 120
3. Use Multiple vLLM Instances
Deploy separate instances for different workload types:
Route requests based on expected length using a load balancer or API gateway.
4. Enable Continuous Batching
vLLM's continuous batching (enabled by default) allows new requests to join ongoing batches:
# This happens automatically, but ensure you're not disabling it
engine_args = EngineArgs(
enable_prefix_caching=True, # Helps with repeated prompts
gpu_memory_utilization=0.9, # Use most GPU memory
)
5. Implement Client-Side Strategies
- Request pooling: Group similar-length requests from the same client
- Timeout handling: Set appropriate timeouts based on request complexity
- Retry logic: Implement exponential backoff for failed requests
6. Monitor and Adjust
Track these metrics per client:
- Time to first token (TTFT)
- Tokens per second
- Queue waiting time
Use this data to dynamically adjust routing rules and instance allocation.
7. Advanced Configuration Example
Here's a production-ready setup with multiple instances:
# Instance for short requests
short_instance:
model: "your-model"
max_model_len: 2048
max_num_seqs: 64
max_num_batched_tokens: 8192
# Instance for long requests
long_instance:
model: "your-model"
max_model_len: 8192
max_num_seqs: 16
max_num_batched_tokens: 16384
8. Use Scheduling Policies
If using Kubernetes or similar orchestrators:
- Implement pod autoscaling based on queue depth
- Use priority classes for different client tiers
- Set resource quotas per client namespace
This multi-pronged approach ensures that clients with long requests don't block those with short ones, while maintaining overall system efficiency. The key is finding the right balance for your specific workload mix through monitoring and iterative tuning.