sched-sim ⏱️
A high-fidelity, CPU-first discrete-event simulator (DES) for LLM serving schedulers.
In modern inference clusters (vLLM, TGI, TensorRT-LLM, SGLang, DistServe), the scheduling policy is the single largest determinant of cluster throughput, latency, and hardware cost. While continuous batching and Paged KV-caching provide the mechanism for dynamic execution, the scheduler determines:
- Which requests enter the next forward iteration.
- How large prompt prefills are chunked to prevent decode starvation.
- What happens when the physical KV-cache runs out of memory (swapping to CPU DRAM vs eviction and recomputation).
- When to disaggregate prefill and decode phases onto specialized GPU worker pools (Splitwise / DistServe architecture).
Testing these policies on real GPU clusters (e.g. 8x H100 nodes) is slow, noisy, and expensive ($20–$50/hr). sched-sim simulates hours of multi-GPU serving traffic in seconds on any standard CPU, using analytical performance models calibrated on, and checked out of sample against, real serving runs measured with servebench and mini-infer.
⚡ Core Architecture
┌────────────────────────────────────────────────────────┐
│ Arrival Process │
│ (Poisson, Bursty Gamma, LMSYS / ShareGPT Traces) │
└───────────────────────────┬────────────────────────────┘
│ Request arrives (prompt_len, output_len)
▼
┌─────────────────────────────┐
│ Waiting Queue │
│ (FCFS, SJF, Priority, SLO) │
└──────────────┬──────────────┘
│ Iteration Scheduler
▼
┌──────────────────────────────────────────────────────────────┐
│ Continuous Batching Step (Iteration) │
│ ┌────────────────────────────┐ ┌──────────────────────────┐ │
│ │ Prefill Tokens (Chunked) │ │ Decode Tokens (1/req) │ │
│ └────────────────────────────┘ └──────────────────────────┘ │
│ ▲ ▲ │
│ │ Paged KV Allocator │ Memory Check │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────────────────┐ ┌──────────────────────────┐ │
│ │ Paged KV-Cache Pool │ │ Preemption Subsystem │ │
│ │ (Physical 16-tok Blocks) │ │ (Recompute vs CPU Swap) │ │
│ └──────────────────────────┘ └──────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
⏱️ Quickstart in 30 Seconds
Installation
# Install via pip
pip install sched-sim
# Or via uv
uv add sched-sim
# Or direct from source for development
git clone https://github.com/Prajwal7-2002/sched-sim.git
cd sched-sim
uv sync
1. Run a Simulation Scenario
Simulate Chunked Prefill serving a long-context RAG workload on an NVIDIA A100 SXM4 (80GB) cluster running Llama-3-8B:
sched-sim run --scheduler chunked --workload rag --hardware a100 --duration 10
Runs 100% on your CPU: You do not need an A100 or any GPU to run
sched-sim. It simulates hours of multi-GPU serving traffic in seconds on any standard CPU. The--hardwareflag tells the discrete-event engine which cluster architecture to mathematically simulate (a100,h100,t4,rtx3050, or a custom JSON profile).
2. Compare Schedulers Side-by-Side (Identical Trace)
Benchmark all 5 scheduling policies on the exact same Poisson arrival trace:
sched-sim compare --schedulers fcfs,sjf,chunked,slo,disaggregated --workload rag --hardware a100
3. Replay Real-World Conversation Traces
Replay Chatbot Arena conversation traces through the simulator:
sched-sim trace ./traces/lmsys_sample.json --scheduler chunked
4. Sweep Load to Discover Saturation Knees
Discover the exact request rate where each scheduler hits its Goodput cliff:
sched-sim sweep --schedulers fcfs,chunked,slo,disaggregated --workload rag --min-rate 2 --max-rate 18 --step 4
5. Check Silicon Hardware Presets
Inspect calibrated hardware profiles:
sched-sim info
💡 Runnable Python Examples
Explore self-contained runnable scripts under examples/:
examples/01_radix_prefix_caching.py: SGLang-style Radix tree prefix caching, prompt matching, and zero-copy block sharing.examples/02_simulate_schedulers.py: Side-by-side simulation comparing FCFS vs Cache-Aware scheduling on shared RAG contexts (69.5% TTFT reduction).examples/03_perfetto_trace_export.py: Programmatic execution and Catapult JSON trace export for ui.perfetto.dev.
python examples/01_radix_prefix_caching.py
python examples/02_simulate_schedulers.py
python examples/03_perfetto_trace_export.py
🔬 The 6 Core Schedulers
| Scheduler | Architecture & Policy | Key Trade-Off |
|---|---|---|
Cache-Aware |
Radix-Tree prefix caching (SGLang / vLLM APC). Shares physical 16-token KV blocks with LRU eviction and prefix-affinity prioritization. | Near-zero TTFT for RAG, multi-turn chat, and shared system prompts. |
Chunked |
Token budgeting (Sarathi-Serve / vLLM). Slices prompt prefills into 512-token chunks. | Eliminates TPOT latency spikes and ensures steady iteration times. |
SLO-Aware |
Dynamic deadline scheduling (EDF) with selective dropping of unrecoverable requests. | Maximizes Goodput (% of requests meeting both TTFT and TPOT SLOs). |
Disaggregated |
Splitwise / DistServe architecture: separates compute-bound Prefill workers from memory-bound Decode workers. | Zero decode interference; models KV-cache interconnect transfer delay. |
SJF |
Shortest-Job-First (shortest prompt first). | Minimizes average waiting time and mean TTFT, but starves heavy RAG prompts. |
FCFS |
First-Come First-Served continuous batching with atomic prefills. | Simple, but large prompts cause Head-of-Line blocking and decode starvation. |
🎨 Interactive Perfetto / Chromium Timeline Visualization
Export native Chromium / Catapult Trace Event JSON files and inspect discrete forward-pass iteration slices and per-request lifecycles in ui.perfetto.dev:
sched-sim run --scheduler cache_aware --workload rag --hardware a100 --trace-out trace.json
Drag and drop trace.json directly into Perfetto to visually analyze:
- Prefill vs. Decode vs. Mixed Slices: Microsecond-accurate forward pass durations on the GPU accelerator.
- Request Streams: Exact arrival, TTFT first-token timestamps, and completion times.
- Counter Tracks: Real-time GPU KV-cache memory utilization (%) and concurrent batch stream counts.
🛠️ Hardware Calibration (Analytical Roofline Model)
sched-sim estimates each step's latency from roofline mechanics plus two measured engine overheads:
-
Prefill Latency ($T_{\text{prefill}}$): Compute-bound matrix multiplication: $$T_{\text{prefill}} = \max\left(\frac{2 \cdot P \cdot N}{\text{Effective TFLOPS}}, \frac{\text{Weights}}{\text{Bandwidth}}\right) + T_{\text{launch}}$$
-
Decode Latency ($T_{\text{decode}}$): Memory-bandwidth bound weight and KV-cache gather: $$T_{\text{decode}} = \max\left(\frac{P \cdot b_w + L_{\text{total}} \cdot \text{KV_bytes_per_token}}{\text{DRAM Bandwidth}}, \frac{2 P B}{\text{Effective TFLOPS}}\right) + T_{\text{launch}} + B \cdot T_{\text{seq}}$$
$b_w$: bytes per weight (
weight_bytes_per_param, e.g. ~0.6-0.8 for 4-bit GGUF; defaults todtype_bytes). $T_{\text{seq}}$: per-sequence cost (per_sequence_overhead_ms: sampling, per-sequence attention and bookkeeping), so a batch of $B$ costs more than a batch of 1. -
Interconnect Transfer ($T_{\text{transfer}}$): Network serialization delay for PD Disaggregation: $$T_{\text{transfer}} = \frac{L_{\text{prompt}} \cdot \text{KV_bytes_per_token}}{\text{Network Bandwidth}} + T_{\text{net_latency}}$$
🔬 Validation Against Real Serving Runs (RTX 3050 6GB Laptop)
Measured with servebench: closed loop at 1, 2 and 4 users, ~286-token prompts,
128 output tokens, 24 requests per level. Raw data in benchmarks/data/; full table in
benchmarks/RESULTS.md.
Method (out of sample). Model architecture, bytes per weight and memory bandwidth (121.5 GB/s, measured with a device-to-device copy) are fixed inputs. Three engine constants (step overhead, per-sequence overhead, prefill efficiency) are fitted on the smallest model's 1- and 2-user runs only. Every other row is a prediction that used no data from that row. The simulator runs the same closed loop as servebench.
| Engine | Held-out rows | Decode TPOT error | Prefill TTFT error |
|---|---|---|---|
| Ollama 0.35.1 (llama.cpp, 4-bit) | 0.5B at 4 users; 1.5B and 3B at 1/2/4 users | within ±12% on 6 of 7 rows (1.5B at 4 users: +84%) | +9% for 0.5B; +34% to +100% for 1.5B/3B |
| mini-infer 0.2.9 (PyTorch, bf16) | 0.5B at 4 users; 1.5B at 1/2/4 users | −13% to +28% (engine is CPU-bound and noisy) | −56% to −69% |
What this tells you:
- Decode under batching is predicted well for an efficient engine: one 0.5B calibration predicts the 3B model's per-token latency within ±5% at every load.
- Prefill does not transfer across model sizes. Prefill efficiency fitted on 0.5B (27% of peak) is too low for larger models, whose bigger matrix multiplications use the GPU better, so TTFT is overpredicted. Calibrate prefill on a model close in size to the one you simulate.
- The simulator assumes vLLM-style fused batches. mini-infer prefills each waiting request in its own forward pass, so real TTFT under load is much higher than the fused-batch prediction. Simulated scheduler comparisons are only as good as that assumption for your engine.
- Earlier versions showed 3-15% "validation errors" that were in-sample: the script derived bandwidth and launch overhead from the same measured TPOT it then reported. That table has been replaced (v0.2.3).
Reproduce: uv run python benchmarks/validate_flagships.py (CI runs the same check in tests/test_validation_benchmark.py).
📊 Telemetry & Reports
Every run outputs comprehensive telemetry:
- Latency Percentiles: TTFT (p50, p90, p99 ms), TPOT (p50, p90, p99 ms/tok), End-to-End latency.
- Goodput Ratio: Exact percentage of requests meeting both TTFT and TPOT Service Level Objectives.
- Preemptions & Recomputations: Total memory thrashing events and discarded tokens.
- Visual Gantt Timeline: Live ASCII/Unicode GPU iteration breakdowns.
- Export: JSON (
--output report.json) and Markdown (--output report.md).
🧪 Testing
Run the deterministic test suite:
uv run pytest
🤝 Contributing
Contributions from systems engineers and researchers are welcome! Check out the Contributing Guide for architectural invariants, testing standards, and high-impact areas where we need help (new scheduling policies, modern hardware presets, and interconnect topologies).
📄 License
Apache 2.0. See LICENSE for details.
Metadata
Release files for sched-sim 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sched_sim-0.2.3.tar.gz | 42.8 kB | With provenance | Details for sched_sim-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sched_sim-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for sched_sim-0.2.3-py3-none-any.whl |
Total release size: 93.3 kB
Release files / sched_sim-0.2.3.tar.gz
| Download URL | sched_sim-0.2.3.tar.gz |
|---|---|
| Size | 42.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d4c0558b0d9ce26cb5ee7ab0b3cc22314ca28c7f619d402f6e180eccee11e12
|
|
BLAKE2b-256 checksum How to use checksums |
3783b0800642cc8b4a80010fb0db3cfef322141c8aa070fe5c7426ae7edca017
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / sched_sim-0.2.3-py3-none-any.whl
| Download URL | sched_sim-0.2.3-py3-none-any.whl |
|---|---|
| Size | 50.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b3a05b66a7cb99942dd91b0ec21d832e1a800a32154b758ff89b947c3996c8e6
|
|
BLAKE2b-256 checksum How to use checksums |
44b139a0e3b8d5ac81b7f0cc059ae8c393adf4522817dc0d44791af619eb2142
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for sched-sim 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sched_sim-0.2.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.