Theoretical Guide: Queueing Theory, Roofline Models, & Network Physics
This document details the mathematical models used inside sched-sim's discrete-event simulation engine.
1. Roofline Latency Modeling
Prefill Stage (Compute-Bound)
During prompt prefill, the model processes \(N\) input tokens simultaneously in a batched matrix multiplication. The execution time is bounded by:
Where: * \(P\) = Parameter count (e.g., \(1.54 \times 10^9\) for Qwen2.5-1.5B). * \(\text{Effective TFLOPS} = \text{Peak TFLOPS} \times \eta_{\text{efficiency}}\). * \(T_{\text{launch}}\) = CUDA kernel dispatch latency (~0.05–0.10 ms).
Decode Stage (Memory-Bandwidth Bound)
Autoregressive token generation generates 1 token per sequence. In each iteration step, the GPU must stream all model weights from DRAM plus the accumulated Key-Value tensors across the active batch \(B\):
Where \(D_{\text{kv\_token}}\) is the bytes per token across all layers: $\(D_{\text{kv\_token}} = 2 \times N_{\text{layers}} \times N_{\text{kv\_heads}} \times D_{\text{head}} \times \text{dtype\_bytes}\)$
2. Prefill-Decode Disaggregation (PD Split) Networking
In disaggregated serving (DistServe, Splitwise), prefill workers stream finished KV-caches to decode workers over high-speed interconnects (PCIe Gen4/5, NVLink, 100GbE):
When network bandwidth is sufficiently high (e.g. 100–400 Gbps), transfer latency is a negligible fraction of decode time, completely isolating decode streams from prefill latency spikes.
3. Queueing Dynamics (\(M/G/1\) Queues)
In an idealized serving system with Poisson arrivals (rate \(\lambda\)) and general service distribution \(S\), the expected waiting time in queue \(W_q\) is given by the Pollaczek–Khinchine (P-K) formula:
Where: * \(\rho = \lambda \cdot \mathbb{E}[S]\) is the cluster utilization. * \(\mathbb{E}[S^2] = \text{Var}(S) + (\mathbb{E}[S])^2\) represents the second moment of service time.
Why Variance Kills Latency:
In asymmetric workloads (such as RAG, where prompt lengths range from 50 to 5,000 tokens), the variance \(\text{Var}(S)\) is enormous. The P-K formula proves that high variance in service time explodes waiting time \(W_q\) even when average utilization \(\rho\) is moderate!
Chunked Prefill directly dampens \(\text{Var}(S)\) by enforcing uniform chunk execution steps, driving queue waiting times down dramatically.