Simulate LLM load balancing policies
CPU · your Macnotebook120 minrequiredGoal · A discrete-event simulation of N replicas serving requests with heavy-tailed prompt and output lengths, comparing p50 and p99 latency under round-robin, least-outstanding, and prefix-aware routing.
- 1Model a replica as a server with continuous batching where step time grows with batch size (for example 20 ms plus 0.5 ms per sequence) and a max batch of 64.
- 2Generate 5000 requests with Poisson arrivals, log-normal prompt lengths, and output lengths from 16 to 1024 tokens; tag 40 percent with one of 10 shared prefixes.
- 3Implement round-robin, least-outstanding-requests, and prefix-aware (hash prefix to replica, fall back to least-outstanding when overloaded) routers.
- 4Give prefix hits a 60 percent shorter prefill time to model KV reuse.
- 5Run each policy at 4 replicas and arrival rates at 50, 80, and 95 percent of capacity; record p50 and p99 end-to-end latency and per-replica utilisation variance.
- 6Plot p99 versus load for the three policies.
- Deliverable
- lb_sim.ipynb with the p99-versus-load plot and a summary table.
- Check
- At 95 percent load round-robin p99 is at least 1.5x the least-outstanding p99; prefix-aware has the lowest mean latency but higher utilisation variance across replicas.