kv-routing-sim
A calibrated instrument, plus a replication.
kv-routing-sim is a trace-driven simulator for LLM serving on several replicas. It models the prefix cache of each replica and the routing of requests between them. The cache model was checked against the counters of a live vLLM, and the error is published here. The routing result is not new: others published it first, and this project only repeats it. Every test was written down before it ran. The tests that failed are in the table below, together with the others.
The simulator has also replayed a public trace of 739 coding-agent sessions end to end, at its recorded size (53,967 requests, 7.8 billion prompt tokens). That run covers cache accounting and routing only. It has no timing.
Run it on your traffic in the browser. There is nothing to install, and the log you choose is never uploaded.
What was checked, and how far off it is
| Checked against | A live vLLM 0.30.0 (--enable-prefix-caching) serving Qwen/Qwen3-4B on 2× Tesla T4. The check uses the engine's own counters, vllm:prefix_cache_hits ÷ vllm:prefix_cache_queries, and the cached tokens of each request |
| Cache model | Exact on one trace of 120 requests sent one at a time, once with 1-token answers and once with 64-token answers, with the cache under eviction pressure. Every counter and every request matched, in three identical runs of each. Exact again on vLLM 0.34.0, with the same test (V1). On two live replicas, hit rates within 1.4% under three routing policies (1.6% with the engine fixed in 0.2.0) |
| Timing model | p95 TTFT within 1.41× on traffic it never saw. p95 time per output token within 7% around a 100 ms limit. ⛔ It fails at the knee of a GPU's load curve: there the mean time per token is 1.5–1.7× off, and a second calibration put one p95 TTFT 4.17× off |
| Routing result | On a T4, among the standard policies: keep each session on one GPU. This is not a new result. SMetric (2026) reached it on production traces, and LMetric (OSDI '26) had shown why. This project agrees with them, independently (the finding). It also measured how far a GPU count from a simulator can be trusted. Where three calibrations of the same GPU type all give a count (91 of 144 cells), the counts are within one of each other in 86. In 9 more cells, the calibrations disagree on whether the target can be held at all |
Validity: where these numbers hold
| What was used | Do not read a number here as | |
|---|---|---|
| Engine and version | vLLM 0.30.0. Only the cache model was checked again, on 0.34.0 (the release of 16 November 2026), and it was exact on the same test (V1). Timing, GPU counts and rupees were not checked again | true of "vLLM" in general. For timing and cost, true of any version other than 0.30.0 |
| GPU | one Tesla T4 for the exact checks, and two for the two-replica check. Three calibrations of that one GPU type | another GPU's latency, GPU count or rupees |
| Model | Qwen/Qwen3-4B |
another model's numbers. For another model, timing and cache size must be measured again (kvsim calibrate) |
| Replicas | live: 1 and 2. Simulated: 1 to 16, and to 32 under the two-part target | a measured fleet. Above two replicas, every count comes from the simulator |
| Block size and cache | blocks of 16 tokens. 1,537 blocks on a T4, and 512 in the exactness test | valid for another block size or cache size without a new run |
| Trace block size | vLLM caches blocks of 16 tokens. Each public trace hashes blocks of its own size: 64 tokens in AgentX, 512 in Mooncake and 16 in Bailian. Scaled down to fit a T4, one simulator block stands for 1,024 real tokens of AgentX, 512 of Mooncake and 256 of Bailian. The run of the whole AgentX trace (L1) keeps its 64 | the full reuse in those traces. Reuse finer than one block is not seen, so hits on a partly shared prefix are under-counted. Coarse blocks make reuse look smaller than it is, not larger |
| Traffic | for the exactness test, one generated trace of 120 requests (40 sessions of 3 turns, prompts of 383 to 583 tokens), sent one at a time. For the finding, generated agent sessions of 4 turns and about 1,700 prompt tokens. Three public traces, scaled down 16 to 64 times to fit a T4. One of them, AgentX, was also replayed whole at its recorded size, without timing (L1) | production traffic at its real size, sessions of unequal length, or an exact answer for requests that overlap |
What one agent session costs, by routing policy
Each row uses one shared system prompt and 2 sessions a second, with each policy on the fewest T4s that meet the target. A session sends 6,800 prompt tokens in 4 requests. 519 of them are new in this replay. This is text that no earlier request sent, so no routing can avoid computing it. (180 of the 519 are the model's own earlier replies. The replay is open-loop and makes them up. A live engine could still have them in its cache from generating them.) Re-prefilled tokens are the tokens the GPUs computed beyond that. A cache shared by all GPUs would have saved them.
| Target | Policy | T4s | Cache hit rate | Re-prefilled tokens per session (95% interval) | ₹ per session |
|---|---|---|---|---|---|
| p95 time to first token ≤ 2 s | session-sticky | 5 | 92.0% | 27 (7 to 54) | 0.046 |
| round-robin | 7 | 82.5% | 669 (627 to 718) | 0.063 | |
| least-loaded | 10 | 81.2% | 761 (723 to 805) | 0.089 | |
| balanced prefix-affinity | 10 | 86.0% | 431 (392 to 475) | 0.091 | |
| and p95 time per output token ≤ 100 ms | session-sticky | 10 | 91.5% | 61 (27 to 102) | 0.092 |
| least-loaded | 13 | 80.8% | 787 (741 to 840) | 0.118 | |
| round-robin | 14 | 80.1% | 834 (785 to 889) | 0.126 |
These numbers are simulated, on calibration A of one T4 (vLLM 0.30.0, Qwen3-4B), with generated
traffic. The intervals are bootstrap intervals over sessions. Rupees are for a T4 at $0.526 an hour
and ₹95.87 a dollar, both cited and dated in configs/cost_model.yaml. The grid ran six policies.
A policy with no row did not meet the target at any GPU count of the grid: pure prefix-affinity and
prefix-affinity with a load weight of 1 under the first-token target, and every form of
prefix-affinity under both targets. A higher hit rate does not mean fewer GPUs. Prefix-affinity
sends the sessions that share a prompt to the GPUs that already hold it. Those GPUs get more of the
load, and the p95 time to first token follows the busiest one. kvsim replay checks both targets
by default (--tpot-slo-ms 0 sizes on the first token alone). Session-sticky's 27 tokens are the shared prompt, computed once
on each extra GPU. That is a one-time cost of 4 × 1,360 tokens, not a rate. Per session it would be
half as much in a trace twice as long, and its interval only shows which sessions paid it.
Round-robin's 669 is mostly a rate. Rupees are counted over the whole run of a short trace. A
service that ran all day at this rate would pay about a quarter less. This test was registered
before it ran, as S1: the report, made by
scripts/session_cost.py.
Every registered test, and what happened
Each prediction was committed before its test ran. Of 21 rows, 11 held (H4 only in an amended form), 4 failed, and 6 held in part or are not settled.
| Test | Predicted | Outcome |
|---|---|---|
| H1 | prefix-affinity routing has a higher cache hit rate than least-loaded at every replica count | ⛔ failed: true at 1–2 sessions/s, gone or reversed from 3/s |
| H2 | there is a sharing ratio above which prefix routing wins | ⛔ failed: pure prefix-affinity loses at every sharing ratio above 0 |
| H2b | prefix routing pays once tenants' prompts outgrow one GPU's cache | ✅⛔ not settled: held on the first timing model. On the checked one it failed on calibrations A and C and held on B (C held with the engine of 0.1.2) |
| H3 | calibration error in single digits (%) on two workload shapes | ✅ held: zero error on two shapes, +0.3% on a third |
| H4 | the residual of a naive cache model is eviction-order skew | ✅ held, in an amended form: it is capacity skew (−11.9 points) |
| H5 | the cost win is one fewer replica at a fixed target | ✅⛔ in part: only for balanced prefix-affinity at low sharing |
| H6 | the ranking of policies does not depend on the hardware | ✅⛔ in part: the ranking moves (τ-b down to 0.51), but the direction of the flip does not. First timing model only |
| R1 | on the Mooncake trace, prefix-affinity beats session-sticky on tool-agent traffic and never on conversation | ⛔ failed: prefix-affinity did not win on tool-agent traffic. The conversation half held (it failed with the engine of 0.1.2) |
| R2 | on the AgentX trace, session-sticky and balanced prefix-affinity tie | ✅ held, on the first timing model |
| R1, R2 again | the same two on the checked timing model: R1 fails again, R2 holds | ✅⛔ in part: R1 failed again, as predicted. R2 could not be tested as designed |
| R3 | four rules for the two published policies, ported, on a public production trace | ✅⛔ in part: 2 of 4 held |
| Phase 6 | hit rates on two live replicas within 10% | ✅ held: within 1.4%, run twice (1.6% with the engine fixed in 0.2.0). Latency came out 5–222× off, which led to C2 |
| C1 | kvsim calibrate works on a real GPU, and its cache check is exact |
✅ held: 48 of 48 requests |
| C2 | three timing predictions. One of them: a busy second GPU does not slow down the first | ✅ held: all three (1.92×, 1.00×, within 1.41×) |
| C3 | a profile fitted on a real GPU predicts traffic it never saw within 2× | ✅ held: all three (exact, 1.41×, 1.38×) |
| C4 | nine rules for per-token timing on a real T4 | ✅⛔ in part: 7 of 9 held |
| T1 | per-token latency within 1.5× on five held-out runs | ⛔ failed: 1.54× and 1.71× at the knee of the load curve. Within 1.07× away from the knee |
| T2 | with a limit on token speed too, session-sticky is still best or tied | ✅ held, on three calibrations. The GPU counts about double |
| S1 | three predictions for the session cost table above (the table uses grid cells that had already been read) | ✅ held at the registered cell. One of its rules fails in 5 of 86 cells outside it |
| V1 | the cache model, unchanged, is exact on vLLM 0.34.0 too, on the same test | ✅ held: every counter and the cached tokens of all 120 requests, three runs each, with 1-token and with 64-token answers |
| L1 | on the whole AgentX trace at its recorded size: the cache model serves exactly what the raw file allows, round-robin re-prefills at least 4× what session-sticky does, and pure prefix-affinity ties session-sticky | ✅ held: 53,967 of 53,967 requests exact, 35× to 993×, within 0.02 points. No timing |
If you have five minutes
- Every registered test, and what happened: 21 rows. 4 failed, and 6 held only in part.
- The calibration report: the prediction against the measurement, request by request, with the residual explained.
- The finding, as a replication, next to the work that came first (related work).
- What one agent session costs under each routing policy.
- What breaks at 10× and 100×, as measured.
- Ten questions a skeptic should ask, each with its number and where it does not hold.
Evidence ledger: for each result above, the file that holds it, the script or notebook that made the file, and the commit
| Claim | Number | Results file | Made by | Commit |
|---|---|---|---|---|
| Cache model exact with 1-token and with 64-token answers | 3 of 3 runs, on both | phase3.json |
notebooks/phase3_calibration.ipynb |
f7f089e |
| The same test on vLLM 0.34.0 (V1) | 3 of 3 runs, on both | phase3.json |
notebooks/v034_recheck_t4.ipynb |
a5bcb8d |
| A third, concurrent workload (H3) | +0.3% | fitted_profile.json |
scripts/phase3_analyze.py |
bef5a50 |
| What a naive cache model misses (H4) | −11.9 points | phase3.json |
notebooks/phase3_calibration.ipynb |
f7f089e |
| Hit rates on two live replicas (Phase 6) | within 1.4% | analysis.json |
scripts/phase6_analyze.py |
a025690 |
| The same hit rates with the engine fixed in 0.2.0 (post hoc) | within 1.6% | registered_predictions.json |
scripts/registered_predictions_again.py |
145e0a9 |
| Latency on those two replicas, first timing model | 5–222× off | analysis.json |
scripts/phase6_analyze.py |
a025690 |
| The calibration command's cache check (C1) | 48 of 48 requests | c1.json |
notebooks/c1_calibrate_t4.ipynb |
a025690 |
| Timing: three predictions (C2) | 1.92×, 1.00×, within 1.41× | analysis.json |
scripts/c2_analyze.py |
27b8958 |
| p95 time to first token on traffic the fit never saw | within 1.41× | analysis.json |
scripts/c2_analyze.py |
27b8958 |
| One p95 time to first token at the knee, on a second calibration (C3) | 4.17× off | analysis.json |
scripts/c3_analyze.py |
fd7ec58 |
| A profile fitted on a real GPU, on traffic it never saw; an older profile, another day (C3) | within 1.41× and 1.38× | analysis.json |
scripts/c3_analyze.py |
fd7ec58 |
| p95 time per output token around the limit (C4) | within 7% | analysis.json |
scripts/c4_analyze.py |
846ec00 |
| Nine rules for per-token timing (C4) | 7 of 9 held | analysis.json |
scripts/c4_analyze.py |
846ec00 |
| One calibration's own spread covers the next one's GPU count (C4, rule E) | 83.8% of cases | analysis.json |
scripts/c4_analyze.py |
846ec00 |
| Per-token latency at the knee of the load curve (T1) | 1.54× and 1.71× | t1.json |
scripts/t1_itl_check.py |
326fadf |
| Per-token latency off the knee (T1) | within 1.07× | t1.json |
scripts/t1_itl_check.py |
326fadf |
| GPU counts under the two-part target (T2) | a median of 2.00× the first-token counts, on each calibration | analysis.json |
scripts/t2_analyze.py |
f14fb99 |
| GPU counts from three calibrations of one GPU type | 91 of 144 cells have a count on all three: 62 equal, 86 within one; 9 more disagree on holding the target | posthoc_three_calibrations.json |
scripts/c3_posthoc_grid.py |
080f615 |
| Ranking of policies across hardware (H6) | τ-b down to 0.51 | h6.json |
scripts/run_h6.py |
35200a9 |
| Two published policies on a production trace (R3) | 2 of 4 held | analysis.json |
scripts/r3_analyze.py |
20a6821 |
| New tokens in a session | 519 of 6,800 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Session-sticky, first-token target | 5 T4s, 27 tokens, ₹0.046 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Round-robin, first-token target | 7 T4s, 669 tokens, ₹0.063 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Balanced prefix-affinity, first-token target | 10 T4s, 431 tokens, ₹0.091 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Least-loaded, first-token target | 10 T4s, 761 tokens, ₹0.089 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Session-sticky, two-part target | 10 T4s, 61 tokens, ₹0.092 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Round-robin, two-part target | 14 T4s, 834 tokens, ₹0.126 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Least-loaded, two-part target | 13 T4s, 787 tokens, ₹0.118 | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| S1's rupee rule outside its registered cell | more than 10% off in 5 of 86 cells | session_cost.json |
scripts/session_cost.py |
eac9db9 |
| Memory for the block hashes of a 100× trace | 537 MiB for 80,000 requests | scale.json |
scripts/measure_scale.py |
fde6cf6 |
| A public trace replayed whole, at its recorded size (L1) | 739 sessions, 53,967 requests, 7.8 billion prompt tokens | l1.json |
scripts/run_l1.py |
07d0913 |
| At that size, one replica that never evicts against the raw file (L1a) | 53,967 of 53,967 requests exact | l1.json |
scripts/run_l1.py |
07d0913 |
| Computed again with 1 Mi tokens of cache per replica: round-robin, session-sticky (L1) | 46.64% and 1.32% of prompt tokens | l1.json |
scripts/run_l1.py |
07d0913 |
| Engine, block size and cache of the timing profile | vLLM 0.30.0, 16 tokens, 1,537 blocks | t4-qwen3-4b-vllm0.30.0-ctx.json |
scripts/c2_analyze.py |
30e689d |
python scripts/build_ledger.py --check reads every number from its file again and compares it
with this table. Settings such as block size, cache size and replica ranges are in the configs that
the validity table uses. Numbers from other people's papers carry their citation.
Status and known limits (2026-11-28)
Known limits. Replica counts are T4 figures on generated traffic. Another calibration of the same GPU type usually gives a count within one of them. This is true in 86 of the 91 cells where all three calibrations give a count. In 9 more cells, they disagree on whether the target can be held at all. These are also first-token counts. With a limit on token speed too, the simulator needs about twice as many GPUs. (The command applies that limit by default.) The repeats of one calibration do not cover the next calibration's count often enough: 84% of cases, where the rule was 90%. So the tool says "plus one". At the knee of a GPU's load curve no number here is reliable, and the tool says when a recommendation is there. The grid behind the finding has one generated trace per point and three seeds of the router. The methodology asks for five seeds, and a paired interval on every row that compares a policy with the baseline. The test behind half of the old headline was decided inside that margin, so that half is "not settled" below.
Release 0.2.0 fixed a defect of the engine. It was found on 27 November 2026. Every result that it could change was derived again. With 64 prompts, the answer of one calibration changed. The cache counts did not change. See what changed in 0.2.0. The release also fixes how the tool reads your own logs, for example their time order, missing answer lengths and timestamps in milliseconds.
Not new. The routing result was published first (SMetric, LMetric). NVIDIA ships a larger simulator for the same question. Three more simulators checked against live engines were published in October and November 2026. See the note under the finding, and the section on related work.
Upstream. During calibration, this project found a bug in the trace replay of
vllm-project/guidellm: one token is lost per block with tokenizers that add a start token.
Another contributor reported it there, and it is fixed (#1424 and #1425, merged 17 November 2026).
Nothing was filed from this repository.
Demo. The demo page is live at
gitgod-debug.github.io/kv-routing-sim. The package
is on PyPI: pip install kv-routing-sim (see Install).
What changed in 0.2.0
Release 0.2.0 fixes a defect in the simulator's engine. It was found on 27 November 2026, when the engine's code was reviewed against its own rules. When a step finished all the work a GPU had, the engine let the next request start before that step had ended. A real engine runs one step at a time. In the same case the router saw that GPU as idle while it was still computing, and a request was counted as finished when its last step started, not when it ended.
Every stored result that the fix can change was derived again with the fixed engine. The runs were
registered first, in configs/rederive_0_2_0.yaml, and H6 later in
an addendum (see below). The files of release 0.1.2 that changed are kept, byte for byte, in
artifacts/results/v0.1.2/. The old engine is still in the
code (engine_version="0.1.2"). The predictions that were registered before each GPU run were made
with it, so the tests check them with it.
What did not change. Computed again with the fixed engine, every registered prediction of Phase 3 (H3 and H4, and so V1), C1, C2 and C3 is the same, to the token and to the millisecond. So the cache model is exact on the same tests as before, on vLLM 0.30.0 and 0.34.0. The timing checks C2, C3 and T1 give the same factors. The outcome of every registered test is the same. Inside two of them one part changed: H2b on calibration C, and the conversation half of R1.
What changed.
- H2b at 64 prompts and 2 sessions/s. On calibration C, session-sticky now needs 10 T4s and balanced prefix-affinity 10. With the old engine it was 12 and 10. So the registered rule now fails on A and C and holds on B. The question stays not settled.
- Three calibrations of one GPU type: 91 of 144 cells have a count on all three (it was 92). 62 are equal (58) and 86 are within one (89). In 9 cells (8) the calibrations disagree on whether the target can be held at all.
- C4: seven of its nine rules hold, as before. Rule E: one run's own range covers another run's count in 83.8% of cases (82.4%). The rule asked for 90%, so it still fails. Rule F2 still fails, now on one of the three fits. It was two.
- T2: its three rules still hold. With both targets, the GPU counts are a median of 2.00 times the first-token counts on each calibration (1.93 to 2.00). H2b's rules under both targets, looked at after the test and not registered there, now hold on all three calibrations (C failed).
- S1, the session cost table: its three predictions still hold. At one prompt and 2 sessions/s, least-loaded now needs 10 T4s, not 11 (₹0.089 a session, not ₹0.098). The other rows of that table moved by at most 18 tokens and ₹0.001. Its rupee rule fails in 5 of 86 cells outside the registered one (4).
- R1, on the first timing model: still failed. Prefix-affinity still does not win on tool-agent traffic. On conversation it now never wins, as predicted. With the old engine it won at one speed, so that half failed too.
- R2, on the first timing model: holds, as before.
- R1 and R2 on the checked timing model: the same verdicts. R1 fails on both calibrations, session-sticky and balanced prefix-affinity stay within one replica of each other, and R2 could not be tested as designed.
- R3: the same two of four rules hold. SMetric's rule now needs one GPU fewer than session-sticky at the highest load on three calibrations of four (it was all four). Under both targets, which are reported and not tested there, the tie of balanced prefix-affinity and session-sticky now holds as well.
- H6, on the first timing model, was derived again later (see below). Both halves keep their verdicts. The ranking half still fails: τ-b goes as low as 0.51, as before. With the old engine there was one point, in one rescaled regime, where the T4's choice cost at least one GPU more. Now there is none. The crossover half still holds on all four rescaled regimes. In the T4 baseline, which its rule does not test, session-sticky now needs fewer GPUs at 64 prompts and 1 session/s (3 against 4). The old engine gave a tie there.
- The eviction-time histograms of the calibration (H4). This check replays the one-token workload at the times the requests were sent, with the fitted timing. With the fixed engine a request waits when the modelled step before it lasts longer than the real one did. In two of the three runs a few requests then overlap in the model, where the engine ran them one after the other. There the model evicts 968 and 966 blocks, where the engine evicted 963. The distributions are now 0.074 to 0.095 apart (the largest CDF distance), where they matched exactly. That exact match came partly from the defect. The exactness test itself sends the requests one at a time with no timing, and it did not change.
The registration missed two things. First, its own check failed in one cell. It said that no hit rate or cached-token count of H3, H4, V1, C1 and Phase 6 may move, and that a move would mean the fix is wrong. One of Phase 6's six predicted hit rates moved: session-sticky with 64 prompts, from 0.8214 to 0.8230. Session-sticky sends a new session to the replica with less work, and the fixed router sees the step that is still running there. So a few sessions start on the other replica. The registration had assumed that time could not move Phase 6's counts, and for this policy that was wrong. The fix stays, because the router's view is one of the three parts of the defect. Phase 6's stored result compares the live engine with the predictions registered before that run: within 1.4%. With the fixed engine's predictions it would be within 1.6%, and its rules would still hold. Two of C4's predictions move too, by less than half a millisecond. The details are in a post hoc report: the registered predictions, computed again.
Second, one stored result was not on its list. The pre-check of C3, a post hoc analysis, uses the engine too. It was found by comparing every script that calls the engine with the registered list, and it was derived again. Four of its numbers moved, and its conclusion did not.
A note on the registration. The registration file says what was known before the runs. A scratch run of the fixed engine had given H2b's rule as holding on all three calibrations. That run had only the first part of the fix. With the whole fix, the rule holds on B only. The file stays as it was written.
H6, derived again later. The registration kept H6 on the engine of 0.1.2, because of the rule
made when it failed: a failed test is not repeated until it passes. That rule is about running a
test again to get a new verdict. Here the rules and the configs stay the same, and only the engine
changes. So after a second review, H6 was derived again too, as registered in an addendum,
configs/rederive_0_2_0_h6.yaml. A scratch run during that
review had already shown the result, and the addendum says so.
Not derived again. L1 was kept by the registration, which says that its steps take no time. That is not exact: they take a nanosecond. So L1 was run again with the fixed engine. Every count came out the same, and only the run times differ, so its stored files stay. The scale test measures this machine. The speed probes of R1, R2 and R3 chose those tests' speeds before the tests were registered, so they stay as they are.
How a log is read. A first review fixed how the tool reads a user's own log: its time order, missing answer lengths, repeated request ids and the scale of AgentX traces. A second review before this release found more gaps, and 0.2.0 closes them too:
- A log with timestamps in milliseconds was read as seconds, which made the load a thousand times lower. Such a log is refused now.
- When lines are skipped, or when a request's
max_tokensstands in for a missing answer length, the report says so next to its recommendation. Before, only the statistics at its end did. - AgentX sessions that share an id are kept apart and counted. Before, they were read as one session that re-read its own blocks.
- A copy of a shipped profile, given as a file, warns about prompts outside its measured range, as the profile does when it is given by name.
- A value of the wrong type is refused:
truewhere a count belongs, or"false"in quotes forcalibrated. - The fleet size, the token scale and the arrival rate have limits. An unwritable output path, a malformed engine address and a line nested too deep now end in one line, not in a traceback.
Ten questions a skeptic should ask
| Question | Answer, with its number | Where it does not hold | |
|---|---|---|---|
| 1 | "Exact" on what? | On one trace of 120 requests, sent one at a time to one replica, once with 1-token answers and once with 64-token answers, three identical runs each. Every counter and the cached tokens of every request matched. On a concurrent run: +0.3%. On two live replicas: within 1.4% (1.6% with the engine fixed in 0.2.0) | Nothing concurrent is exact. One model, one GPU type |
| 2 | vLLM 0.30.0 is four releases old. Is this still true? | For the cache model, yes. The same exactness test ran on vLLM 0.34.0 on 2026-11-25, registered first (V1). It was exact with 1-token and with 64-token answers, three runs each | Timing was not checked again. Latency, GPU counts and rupees are 0.30.0 results, and the two-replica check was not repeated |
| 3 | The timing model was once 5–222× off. Why trust it now? | That model had no term for context length. The model used now predicted unseen traffic within 1.41×, and time per output token within 7% around the limit | At the knee of a GPU's load curve it is 1.54× and 1.71× off (T1 failed). The tool warns when an answer is at the knee |
| 4 | How good is a GPU count from this? | Where three calibrations all give a count (91 of 144 cells), they are equal in 62 and within one in 86 | In 5 cells they are two apart. In 9 more they disagree on whether the target can be held at all, once 10 GPUs against "not on 16". The spread of one calibration covers the next one's count in 83.8% of cases, where the rule was 90% (C4). All of this compares calibrations with each other. No count above two replicas has been checked on a live fleet |
| 5 | Is the routing result new? | No. SMetric and LMetric published it first. This project agrees with them, independently, on a small calibrated model | Of four rules for those two policies, ported and run on a production trace, 2 held (R3) |
| 6 | Does session-sticky always win? | With one shared prompt or with four, on all three calibrations, it needs the fewest GPUs or ties | With 64 tenant prompts it is not settled (H2b). Sessions of unequal length are not tested here. SMetric measured a 2.17× imbalance |
| 7 | Rupees per what, and over what time? | Per agent session in the cost table near the top. Per 1,000 requests that met the target on the demo page and in kvsim replay. Both for a T4 at $0.526 an hour and ₹95.87 a dollar, cited and dated in configs/cost_model.yaml |
Counted over the whole run of a short trace. A service that ran all day would pay about a quarter less |
| 8 | Real traffic? | Three public traces, each test registered before it ran. One of them (AgentX, 739 coding-agent sessions) was also replayed whole, at its recorded size. The cache model served exactly what the raw file allows. With 1 Mi tokens of cache per replica, round-robin computed 46.64% of the prompt tokens again, and session-sticky 1.32% (L1) | The time-based tests ran on traces scaled down 16 to 64 times. R1 failed twice, R2 could not be tested on the checked timing model, and R3 held in 2 of 4 rules. The full-size replay has no timing, because no GPU here was timed on prompts that long |
| 9 | What breaks first at 100×? | Memory for block hashes: 537 MiB for 80,000 requests, before the simulation starts | Whether many real replicas stay matched cannot be answered on a CPU. Two live replicas are the most that was measured |
| 10 | Can I rebuild your tables myself? | python scripts/reproduce.py: twenty-one steps, about 13 minutes on a laptop. Every file a step writes is compared with the committed one |
It runs the analysis of each GPU run again, on the raw files stored here. It cannot repeat a GPU measurement. Not covered yet: the first two sweeps, H6, the scale test, the real-trace runs, and the stored grids that some analyses start from |
The finding
Keep each user on one GPU. This holds on three calibrations of the same GPU type (a T4). Session-sticky routing needs the fewest GPUs of the six policies in the registered grid, or ties for the fewest, at every load, with one shared system prompt and with four. It never needs more GPUs than round-robin or least-loaded. It is not settled whether routing by prefix saves GPUs once the tenants' prompts outgrow the cache. The registered test said no on two calibrations and yes on one. Read every GPU count here as the answer of one calibration. Another calibration usually gives a count within one of it.
This is not a new result. A fourth check of prior work found this on 2026-10-05, after three earlier checks had missed it. SMetric (Wang et al., arXiv 2607.08565, July 2026) reached the same advice from production traces on 32 real GPUs: send the follow-up requests of a session to the instance that served it. LMetric (Zhang et al., OSDI '26) had shown before that a hand-weighted mix of a cache score and a load score has no right weight. What this repository adds is an independent agreement on a small calibrated model, from tests registered before they ran.
Both published policies have since been run here, as ports, on a public production trace (R3, registered first). Two of its four rules held, and two of my predictions failed. Under the first-token target, neither policy needs more GPUs than session-sticky at any load. LMetric ties it on three calibrations of four, and needs one fewer on the fourth. SMetric's rule needs one fewer at the highest load on three calibrations of four (6 against 7), and ties on the fourth. With a limit on token speed as well, LMetric needs one or two GPUs fewer at the highest load, and SMetric's rule two or three. That is a reported number, not a tested rule. The ports were written for this repository, so none of this is a result about the two systems themselves.
SMetric also names a weakness of session-sticky routing. Real sessions differ a lot in size, and then the load goes out of balance: 2.17× on its testbed. This did not show on that trace (1.14× at most, because its sessions are short), and every generated session here has the same number of turns. So this weakness is still not tested in this repository.
Since then, others have measured both sides (found by the check of 2026-11-25). On SGLang, session affinity cut the uncached input by 48.2% and 46.1% compared with round-robin (arXiv 2610.15366). Vesta (arXiv 2610.14686) measured the cost of the pure form. Sending every turn to the instance that holds its cache gave a mean time to first token of 2,819 ms, where SMetric gave 2,060 ms. At higher load it was 5,457 ms against 3,329 ms.
How it was measured: simulated agent traffic, the cache model calibrated against a live vLLM (see
the calibration report below), a context-aware T4 timing model, and a 2-second p95 TTFT target. The
test was registered before it ran, on calibration A, which is C2's fit
(2026-09-30). B and C are the two profiles that
kvsim calibrate wrote on a real T4 in C3 (2026-10-05). B's table was a registered reported item.
C's table was added after seeing it, so it is post hoc
(all three, side by side).
| Distinct system prompts (85 blocks each) | Working set ÷ one T4's cache | Fewest T4s that hold the target at 2 sessions/s, on A · B · C |
|---|---|---|
| 1 | 0.06 | session-sticky 5 · 5 · 5 · round-robin 7 · 7 · 7 · balanced prefix-affinity 10 · not held on 16 · not held |
| 64 offered, 48 used | 2.66 | session-sticky 10 · 12 · 10 · balanced prefix-affinity 10 · 10 · 10 · round-robin 16 · 16 · not held · least-loaded: not held (prefix-affinity with a load weight of 1: 8 · 7 · 8, a weight found after the tests) |
Drawn by scripts/make_figures.py from
demo_grid_ctx.json, which reproduces the table of the
registered re-test exactly. There is one generated trace per point and three seeds of the router,
and a point counts only if every seed holds the target. T4 figures, on calibration A only. On B
and C the 64-prompt points move by up to two replicas, as the table above shows.
Scope: generated traffic, one GPU type (T4), one model (Qwen3-4B). The replica counts are T4 figures on the context-aware model, and another calibration usually gives a count within one replica of them. They are first-token counts. With a limit on the time per output token as well, the simulator needs about twice as many GPUs (T2).
Try it. The demo page (site/)
looks up every point of the re-test's grid: prompts × load (0.25–4 sessions/s) × replicas (1–16) ×
six policies, 6,912 simulator runs. scripts/build_grid.py rebuilds the
grid, and accepts it only if it reproduces the registered table exactly. To open the page from a
clone, run python -m http.server in the repository root, then open http://localhost:8000/site/.
Calibration report: the simulator against a live vLLM
This is a separate kind of claim, so it has its own section. "The simulator matches the live engine within X%" shows that the method is careful. It says nothing about the world. The finding above says something about the world. The two are kept apart here.
| Engine and version | vLLM 0.30.0, V1 engine, async scheduling on (its default) |
| Exact command | vllm serve Qwen/Qwen3-4B --dtype half --block-size 16 --num-gpu-blocks-override 512 --max-model-len 2048 --max-num-seqs 256 --max-num-batched-tokens 8192 --gpu-memory-utilization 0.85 --enable-prefix-caching --kv-cache-metrics --kv-cache-metrics-sample 1.0 --enable-prompt-tokens-details --seed 0 |
| Model and quantization | Qwen/Qwen3-4B, fp16, not quantized. The cache is fixed at 512 blocks (511 usable) by an override, so its capacity is a controlled input and the cache overflows |
| Hardware | Kaggle 2x Tesla T4 (compute 7.5, driver 580.159.04, CUDA 12.8). vLLM runs TRITON_ATTN in fp16 here. For requests sent one at a time, the cache counts do not depend on the hardware. Under concurrency they move with timing (the same workload gave 0.810 and 0.822 on two runs of Phase 6). The order of the policies changes with the hardware (H6), and every latency and cost figure is a T4 figure |
| Hit-rate error against the live engine | Zero on 2 sequential shapes × 3 runs: every counter, and the cached tokens of each of the 120 requests, to the token. +0.3% (relative) on the concurrent shape, predicted by a timing profile fitted without it. Plain LRU on the same runs over-predicts by 11.9 points (W1) and 19.7% (W3) |
| The residual, explained | Sequential: nothing to explain. The engine's kv_block_* histograms, against the model replayed at the times the requests were sent: the counts are exact on W1 (1,880 events) and on one run of W2 (963). In W2's other two runs the timing fit makes a few requests overlap that the engine ran one after the other, and the model counts 968 and 966. The largest CDF distance is 0.042 on W1 and 0.074 to 0.095 on W2. These residuals come from the timing fit, not the cache model. The W1 analysis is post hoc and labelled so |
| The same test on a later engine | vLLM 0.34.0, 2026-11-25 (V1, registered first): the same notebook, with only the engine version changed. Zero error again on both sequential shapes × 3 runs, and +0.7% on the concurrent shape (report). Timing was fitted on it but not checked |
| Check on 2 replicas | Round-robin across two physical T4s: 1,088 prefill tokens computed, 1,088 predicted (Phase 0 v2). Under cache pressure (Phase 6, run twice), the hit rates of all 12 runs were within 1.4% (K1 to four decimals), and within 1.6% with the predictions of the engine fixed in 0.2.0. There were 1,537 blocks per replica and three routers. The engines preempted requests in 8 of the 10 runs where the model predicted none |
| Timing under load | The first profile had no context term and was optimistic. On Phase 6's prompts of ~1,700 tokens, p95 TTFT came out 5–222× its prediction. ✅ Fixed by C2 (2026-09-30, registered): decode cost grows with context (1.92× from 128 to 1,536 tokens), and CPU contention was ruled out (1.00×). The context-aware profile t4-qwen3-4b-vllm0.30.0-ctx, fitted on micro-benchmarks, predicted held-out traffic within 1.10–1.41×. Post hoc, it also predicted Phase 6's two live replicas within 1.02–1.79× (report) |
| Reproduce | The analysis: python scripts/reproduce.py --quick rebuilds this report from the raw files that the GPU run left in this repository, and compares it with the committed one (about a minute, no GPU). The measurement: notebooks/phase3_calibration.ipynb on a Kaggle T4, about 40 minutes (its first cells say how to run it) |
/metrics fields used, by name: vllm:prefix_cache_queries · vllm:prefix_cache_hits ·
vllm:prompt_tokens_by_source{source="local_compute"|"local_cache_hit"} · vllm:num_preemptions ·
vllm:kv_block_lifetime_seconds · vllm:kv_block_idle_before_evict_seconds ·
vllm:kv_block_reuse_gap_seconds (_count and _bucket) · vllm:prompt_tokens · vllm:generation_tokens ·
vllm:num_requests_running · vllm:num_requests_waiting. Also, for each request, the response's
usage.prompt_tokens_details.cached_tokens. TTFT is measured at the client, over streamed responses.
What was predicted, and what the engine did
The predictions were committed before the run
(predictions.json) and measured on the engine
above (calibration_report.md). The
trace has 120 agent requests (40 sessions × 3 turns, one shared system prefix), and each workload
ran three times.
| Workload | Engine (all 3 runs) | Block-pool model (default) | Plain-LRU model (ablation) |
|---|---|---|---|
| W2 one at a time, 1-token outputs | hit rate 0.6090 · 22,664 computed | 0.6090 · 22,664, exact | 0.6073 · 22,760 |
| W1 one at a time, 64-token outputs | hit rate 0.4883 · 29,656 computed | 0.4883 · 29,656, exact | 0.6073 · 22,760 |
| W3 the same trace, concurrent | hit 0.5076 · 27 preemptions · p95 TTFT 41.0 s | 0.509 (+0.3%) · 24 · 38.3 s (−6.7%) | 0.6073 (+19.7%) · 0 · 11.2 s (−73%) |
W1 is the important case. The two models agree when requests hold no decode blocks (W2). They differ by 11.9 points when requests do hold them. vLLM caches full decode blocks, these blocks take space in the same small cache, and they evict useful prefixes. The block-pool model includes this, and LRU cannot see it. On a real engine, the block-pool model was right to the token.
The fitted T4 timing (all of it a T4 figure): prefill 0.70 ms per uncached token, and decode
52.9 ms + 1.23 ms × batch (R² 0.58). It has two limits. They were measured and recorded, not tuned
away (posthoc.md). First, one sequence decodes
slower than two to eight sequences do (63.6 ms per token), and a straight line cannot express
that. Second, the simulator's step model charges a full decode step on top of every prefill, so it
over-estimates the TTFT of an idle replica by ~20 ms.
The hit rate is derived from two counters:
vllm:prefix_cache_hits÷vllm:prefix_cache_queries. There is novllm:prefix_cache_hit_ratemetric (checked againstv1/metrics/loggers.pyat v0.29.0). The old V0 gauge was removed together with V0.
What it does
- Trace input. It reads serving logs (vLLM-style JSONL, OpenAI-style request logs) and three public trace formats (Mooncake, AgentX, Qwen-Bailian) into one normalized, versioned request schema. Prompts are hashed at the adapter boundary and never enter the simulator. So the user content of a trace stays out of memory and out of the output files.
- A block-level KV cache model for each replica. The default model follows the block pool of vLLM 0.30.0 line by line: reference counts, freeing from the tail, cached decode blocks, admission by free memory, and preemption. A plain LRU model is kept next to it for comparison. Many simulators have such a model. What this project adds is a measurement of how close it is to the real engine.
- Nine routing policies. Seven are standard: round-robin, least-loaded,
power-of-two-choices, consistent-hashing-on-prefix, radix-prefix-affinity,
radix-prefix-affinity-balanced (affinity with a load term, as production routers do it) and
session-sticky. Two are ports of published policies, and you must ask for them by name:
lmetric(LMetric, OSDI '26: new prefill tokens × batch size, with no weight to tune) andsmetric-local(SMetric's session rule, arXiv 2607.08565, without its global cache tier). The ports were written for this repository, so a result from them is not a result about the authors' systems. Each policy is one file, and a new policy is a new file.--policies allmeans the first seven, as in every registered sweep. - Sweep and recommendation. It runs policy × replica count (1–8) and draws Pareto curves over hit rate, p95 TTFT and ₹ per 1k successful requests. Then it recommends one configuration and says how much better it is than the naive baseline.
- A check against live replicas. Three fixed routing policies ran on two live vLLM replicas, and their hit rates were compared with the predictions (Phase 6). A recommended configuration has not been deployed.
A generator for agent traffic
An agent sends the system prompt, the tool definitions and the whole conversation again in every turn. So in agent traffic, most of each prompt is shared text. The generator makes traffic of this shape, and the prefix-sharing ratio is one of its parameters.
Install
In a browser, with nothing installed: run it on your traffic.
The simulator runs inside the page with Pyodide. A log you choose is read on your computer and is
never uploaded. The page shows the kvsim commands that give the same answer.
On your machine:
pip install kv-routing-sim # CPU-only, no GPU dependency
kvsim generate --out trace.jsonl --sessions 100 --turns 4 --rate 0.5 # or use your own log
kvsim replay trace.jsonl --policies all --replicas 1-8 \
--profile t4-qwen3-4b-vllm0.30.0-ctx --cost-model default
That takes about half a minute and ends with a recommendation for a T4.
For the newest code on GitHub instead of the last release, install with
pip install git+https://github.com/gitgod-debug/kv-routing-sim.
Set your own target and GPU price with --ttft-slo-ms, --tpot-slo-ms and --gpu-price-usd.
It runs on your laptop, and your trace never leaves your machine. Prompts are hashed at the adapter
boundary, so prompt text never enters the simulator. One caution: a log that has text but no token
ids (--format-in openai-log) is hashed with about four characters counted as one token. The block
boundaries then differ from the engine's, and this biases the hit rate. If you can, use a log with
token ids or block hashes.
What your own log needs. kvsim replay reads one request per line. For a vLLM-style log
(--format-in vllm-jsonl, the default), each line is a JSON object with these fields:
| Field | What it is |
|---|---|
timestamp |
When the request arrived, in seconds. Seconds since the epoch, seconds from any start, and ISO 8601 times all work. Milliseconds are refused: read as seconds, they would make the load a thousand times lower |
prompt_token_ids |
The prompt as the engine's own token ids, after the chat template. A prompt given as text also works, with the caution above |
num_generated_tokens |
How many tokens the answer had. A line without it is skipped. If the line has only the request's max_tokens, that limit stands in, and the report says so |
session_id |
Optional. Session-sticky routing needs it |
request_id |
Optional. A repeated id is renamed |
The lines can be in any order. The report counts every line it could not use, by reason. It also
warns next to its recommendation when lines were skipped, because the fleet is then sized for less
traffic than the log had. --format-in openai-log reads chat-completion logs with a usage block.
Three public trace formats are read as they are published: mooncake, agentx and bailian.
The profile in that command was measured for this project, on a Tesla T4 with Qwen3-4B and vLLM
0.30.0. It ships with the package, and so does the cited cost model. Without --profile, the
timings are a built-in guess. Use the context-aware profile. It is the one checked against live
latency (C2), with prompts up to about 2,000 tokens. The first profile, t4-qwen3-4b-vllm0.30.0,
has no context term. It is kept for the record and is optimistic on long prompts.
kvsim profiles lists what each profile was measured on and checked against. Give it --gpu,
--model, --engine-version, --block-size and --max-num-seqs (or --engine and a running
vLLM), and it says which of these five differ from your setup and what each difference means.
Nothing is interpolated between profiles. A replay also tells you how many of your prompts are
longer than any prompt its profile was timed on. (--profile also takes a path to any profile
file, and --cost-model a path to your own YAML. The shipped files are byte-for-byte copies of
configs/profiles/ and configs/cost_model.yaml.)
The target has two halves by default: p95 time to first token ≤ 2 s, from the cost model, and
p95 time per output token ≤ 100 ms, from the command (--tpot-slo-ms, and 0 turns that half
off). On a T4 the second half is the hard one. Expect about twice the GPUs of the first-token
tables above, and "no configuration met the SLO" on a small fleet.
To get numbers for your own setup, point kvsim calibrate at your running vLLM (with prefix
caching on). It fits C2's context-aware timing model to your GPU and model. It times decode steps
at several context lengths and batch sizes, and prefill at several prompt lengths and after a
cached prefix. It reads the KV capacity from the engine, and it checks the cache model against the
engine's own counters. This takes a few minutes and needs nothing beyond the core install:
kvsim calibrate --engine http://localhost:8000 --out mine.json
kvsim replay trace.jsonl --policies all --replicas 1-8 --profile mine.json --cost-model default
If the cache check misses (by more than 5%, or on the cached tokens of any single request), the profile is written but not marked as calibrated, and the command exits with code 1.
Tested on a real T4 twice, and both tests were registered before they ran.
- C1: its cache check was exact for the cached tokens of all 48 requests (9,840 of 13,776 tokens). It read the engine's 1,537 blocks correctly, in 48 seconds (report). That version fitted a straight line with no context term, and C2 then showed that such a line is up to 7× optimistic.
- C3 (2026-10-05): the command as it is now. It fits C2's context-aware model. It also times new tokens after a cached prefix, because agent traffic is mostly made of that case. (A check on C2's recorded data had shown that timing only cold prompts would have put a held-out p95 off by 5.7–7.2×. That check is post hoc: pre-check.) On the T4 it ran in 160 seconds and was exact on the cache check again. It wrote a profile that predicted three workloads it had never seen within 1.41× on p50 and p95 TTFT. One of those workloads had prompts half as long as anything the model had been tested on. The profile that C2 fitted five days earlier, on another software image, predicted the same traffic within 1.38×, from numbers written down before the run (report).
Near saturation, one fit is not enough. A second run on the same engine, 25 minutes later, gave coefficients 3–5% different. For the one workload at the knee of the load curve, that put a p95 4.2× off. The other five numbers stayed within 1.36×.
So the tool now shows how firm its answer is. Since 2026-10-05, kvsim calibrate measures
every timing cell three times. Next to the fit on all the data, it keeps the fit of each repeat
alone. kvsim replay sizes the fleet on each of those fits too, and prints the result next to its
recommendation:
How firm: 3 to 4 replicas across the calibration's 3 repeats taken alone; size for the larger, plus one.
That range is how much the repeats of one calibration disagree. It is a floor on the uncertainty, not a confidence interval. It knows nothing about another day or another software image. A profile without repeats (like the two shipped ones) says that its spread is unknown.
That floor was measured, and the registered test of it failed (C4, rule E). The command ran three times on one live T4 in one session, with three repeats each. Across 18 sizing questions and both targets, the GPU count of another run was inside a run's own range in 84% of cases. The rule asked for 90%. With the range widened by one GPU each way, it was 95%. The two runs taken back to back agree with each other (96%). The run taken an hour earlier does not agree with them (78%), and the repeats of one run, six minutes apart, cannot see that. So size for the top of the range, plus one. This is what the tool's own line now says. The command itself works on a real engine with its repeats: it was exact on its cache check all three times, at six minutes a run (report).
It also says how close to the edge its recommendation is. kvsim replay runs the recommended
configuration once more with every timing coefficient 5% larger, which is how much a second
calibration of the same GPU can differ. Then it prints how far the p95 latencies moved:
At the edge: with timings 5% slower this configuration no longer meets the SLO (p95 TTFT 644 to 708 ms (×1.10); p95 time per token 93 to 100 ms (×1.07)). Two calibrations of the same GPU differ by that much: allow one replica more.
The example above ends with this line. When there is room to spare, it reads "Not at the edge",
and the p95s move by about the same 5%. If a p95 moves by more than 1.5×, it reads "At the knee".
That means the fleet is close to saturation, and there the simulator's own latencies were 1.5–1.7×
off on a live GPU (T1). --no-edge-check skips this check.
The 1.5 was chosen after looking at the data (post hoc, and labelled so). On T1's five held-out runs, the 5% slowdown multiplies p95 TTFT by 5.3 and 5.5 on the two runs the simulator got wrong, and by 1.13–1.14 on the three it got right. Nothing else moves by more than 1.21× (table). This is five runs of three workloads on one GPU. It suggests that the check can see the knee, but it is not a validated threshold.
What carries over to your own fleet
Read this before you trust a number. A calibration is fitted to one GPU, one model and one block size. So the answer comes in three levels, and they must not be mixed (ADR-010):
| What you get | What it costs you | |
|---|---|---|
| Policy ranking | Which policy wins on your workload shape, and roughly by how much | ⛔ Not free. H6 was tested and failed (2026-09-28). With a 2× faster GPU, or with prefill 2× cheaper or more expensive, the full order of the seven policies changed (Kendall's τ-b as low as 0.51). One thing held, noticed after the run and not registered: session-sticky needed the fewest replicas at all 48 points. So read a ranking as a result for the T4 used here, unless you calibrate |
| Whether prefix routing pays | Whether prefix-affinity is worth building for your prompts and load | Not settled, even on the T4 used here. With one shared prompt or a few: no. Session-sticky needs the fewest replicas, or ties, on all three calibrations. With 64 prompts, the registered test said no on calibration A (2026-09-30). On the two calibrations added later (2026-10-05), it says yes on one and no on the other. The two policies are up to two replicas apart, and calibrations of the same GPU disagree by that much. On the first timing model (no context term), prefix routing paid once prompts outgrew one GPU's cache, and that flip survived four hardware rescalings (H6's crossover half). But that model was wrong about the engine. So the answer depends on the timing model and on its error bar. Measure yours, more than once |
| Absolute ms and ₹ | p95 TTFT and ₹/1k requests for your fleet | Run kvsim calibrate on your own hardware. It takes a few minutes. The error bar here was measured on one GPU and one model. It does not transfer, and this README will never suggest that it does. On the T4 used here, the first timing model (no context term) was 5–222× optimistic under load. The context-aware model predicts held-out traffic within 1.41× (C2), and so does a profile that kvsim calibrate wrote itself (C3). The exception is the knee of the load curve, where a second run of the command was 4.2× off on one p95. All of that is first-token latency. Time per token is now measured too: there the model is within 7% away from the knee, and 1.5–1.7× too slow at it (T1) |
These numbers are not for your hardware. Run
kvsim calibrateand use your own numbers. The cost model works the same way: every constant is in a config file with a source and a date, so you can disagree with it and run again.
Where it runs
A GPU is used only once: for calibration, offline, before anything is published. Everything that is deployed is plain CPU Python:
- The package, on your machine, from PyPI (
pip install kv-routing-sim). This is the main way to use it. - A static demo page, live on GitHub Pages. It is a precomputed grid with selectors. You can see the recommendation change with the prompts and the load in ten seconds, with nothing installed. There is no server, and every number on the page comes from a committed script with a pinned seed. The page is a demo, not a service. It takes no uploads, because your traces contain your users' prompts and should stay on your machine. The in-browser runner next to it runs the same package inside your browser. A log you choose there is read locally and not uploaded.
- Docs: static pages.
Replaying 80,000 requests through a dict-based trie took 13.5 to 21 seconds on one CPU core (measured). There is nothing for a GPU to do here. This is why a simulator is useful: you pay for the GPU once, for calibration, and then you can ask "what if" thousands of times on a CPU.
Related work, and what is claimed
Other people work on the same problem, and more of them than this README said before 2026-10-05. Three checks of prior work missed NVIDIA's simulator and the two papers below. The fourth check found them.
| Project | What it is, and how this differs |
|---|---|
NVIDIA Dynamo's simulator: ai-dynamo/aisim (called aisimulate until November 2026), "DynoSim" (and aiconfigurator before it, arXiv 2601.06288) |
The closest tool, and a larger one. It replays a saved trace on simulated vLLM or SGLang workers with a block-level prefix cache. (Its tutorial uses the same Mooncake trace as R1 below, and it reads the AgentX traces of R2.) It compares round-robin with Dynamo's KV-aware router, and recommends a minimum GPU count under TTFT and TPOT limits. It has had offline multi-worker replay since March 2026. What I did not find in it (read, not run, 2026-10-05): routing policies other than those two; a published check of its cache model against a live engine (its public accuracy page covers TTFT and TPOT on single-node points with prefix caching off); a cost in money. |
| BLIS (arXiv 2610.14255) · a simulator for SGLang clusters (arXiv 2610.15366) · ROCm InferaSim (arXiv 2611.04032), all from October and November 2026 | Three more simulators checked against live engines, found by the check of 2026-11-25. BLIS models routing and KV-cache management, and reports 6.7% median end-to-end error against vLLM with llm-d. The SGLang one reports a token-hit-ratio error within 1.23 points, and it measures session affinity against round-robin with predictions frozen first. InferaSim has a block-level prefix cache and routing across replicas. Each one is larger than this project. A calibrated simulator of this kind is no longer rare. |
| LMetric (Zhang et al., OSDI '26, arXiv 2603.15202) · SMetric (Wang et al., arXiv 2607.08565) · Preble (Srivatsa et al., ICLR '25) | The closest findings, measured on real clusters. LMetric: multiply new prefill tokens by batch size, and then no weight needs tuning. SMetric: route agents by session, and move a session when its instance would miss the SLO. The routing results of this repository agree with them, and add nothing to them. Both are ported here (lmetric, and smetric-local, which is SMetric's rule without its global cache tier) and were run on a public production trace (R3, above). These are ports, not the authors' systems. |
casys-kaist/LLMServingSim (483★, ISPASS '26) |
A cycle-level simulator that copies vLLM's scheduler and ports its block pool, for each instance. It reports TTFT and TPOT within 1% of a real vLLM run on one profile. Its router is round-robin, random or least-loaded, with no prefix-aware or sticky policy. |
microsoft/vidur (735★, MLSys'24) |
Capacity and parallelism planning. Its canary branch does have a block-level prefix cache and three cache-aware routers. But that branch has not been merged since June 2025, so main (what you install) cannot answer the routing question. |
NetX-lab/Frontier (188★, arXiv 2605.21312) |
Prefix and hierarchical caching, SLA-aware Pareto search, and session-sticky routing. It has no prefix-affinity router: its sticky routing uses the session identity, not a shared prefix. |
azrabano23/disagg-sim |
A teaching tool: it reproduces published scheduling arguments on synthetic workloads. Its own README says it does not fit traces, and points to Vidur for that. |
jahnavi-yelamanchi/cachetrace |
A single-path prompt-construction linter. |
CacheWise (arXiv 2606.16824) · gauravapiscean/agentic-kv-cache |
Prefix-aware scheduling and eviction for coding agents, and single-node eviction policies replayed on the same AgentX and Mooncake traces (that second one finds LRU hard to beat). Both work inside one engine. Neither routes across replicas. |
| vLLM · SGLang · LMCache · Mooncake · AIBrix · llm-d | Production engines, caches and gateways. They implement caching and routing, and do not compare policies. Dynamo was in this row until 2026-10-05, and it ships a simulator. The docs of the others were read again on 2026-11-25, and none was found to compare routing policies across replicas against a live engine. |
What is claimed, after that check. Not an empty niche. Only three things that this repository did and can show:
- A measured calibration. The cache model reproduces the prefix-cache counters of a live vLLM exactly, and its hit rates held within 1.4% on two live replicas under three routing policies (1.6% with the engine fixed in 0.2.0).
- A method. The design, rules and prediction of every test were committed before it ran. The tests that failed are reported as findings.
- Numbers on how far sizing from a simulator can be trusted. A second calibration of the same GPU, 5% different, is 4.17× off at the knee of the load curve. Replica counts from three calibrations are within one in 86 of 91 cells, and in 9 more cells the calibrations disagree on whether the target can be held. The per-token model is right away from the knee and wrong at it.
The routing result itself agrees with published work. It was reached independently, on a free Kaggle GPU.
So the value of this project is in how it was done, not in the idea: the published calibration
error and the error bars. This section said the same before the check. Mike-Ew/kv-cache-routing
specified the same six policies and the same 2-replica validation in April 2026, and never built
it. NVIDIA built a larger one.
What breaks at 10× and 100×
Measured on 2026-09-28 by scripts/measure_scale.py, with one fresh
process per case and one CPU core each. The results are in
artifacts/results/scale/. The base is Phase 4's traffic (200
sessions × 4 turns = 800 requests) on 8 replicas, with the calibrated T4 profile. Each case was run
with round-robin and with balanced prefix-affinity.
| Scale | Question | Answer |
|---|---|---|
| 10× trace length (8,000 requests) | Peak memory (RSS) and sweep time? | 81 MiB peak per process. One run takes 1.3 s (round-robin) to 2.0 s (balanced affinity), after 8 s to generate the trace. Nothing breaks: a default kvsim replay sweep (280 runs, one core) takes minutes. |
| 100× trace length (80,000 requests, 8.5 M block hashes) | What fails first: block-hash memory, the policy inner loop, or the report renderer? | Block-hash memory. The trace alone holds 537 MiB (about 64 bytes per hash, as Python ints) before the simulation starts. The simulation adds 11–35 MiB. The policy loop stays linear: 13.5 s and 21 s, about 10× the 10× case. The renderer does not grow with the trace. Two more limits follow by arithmetic and were not measured. The parallel experiment scripts copy the trace into every worker (11 workers ≈ 6 GiB), and a default one-core sweep is 280 × 13–21 s ≈ 1–1.6 hours. |
| 10× replicas (80 replicas at 10× load) | Does the cache model stay accurate, or does eviction-order skew add up? | This cannot be answered on a CPU. In the model each replica is its own block pool, so errors cannot add up inside the simulator. Whether real replicas stay matched is what Phase 6 checks, on 2 GPUs. 80 replicas are not tested. What was measured: affinity routing scores every replica on every request, so its run time grew 2.4× (2.0 → 4.8 s for the same 8,000 requests), while round-robin stayed flat (1.3 → 1.4 s). |
| A real trace, whole (AgentX: 53,967 requests, 121.6 M block hashes of 64 tokens, prompts up to 894,371 tokens) | Does it run at a recorded size, and does the cache accounting still hold? | Yes, when the block hashes are shared. Reading the trace takes 81 s and 1.3 GiB, because the reader hashes each distinct block of a session only once. Before that change it would have needed about 8 GiB. One run of 8 replicas takes 3.2 to 5.4 minutes on one core. One replica that never evicts served exactly what the raw file allows, for all 53,967 requests (L1, report). Cache accounting only, no timing |
Reproducibility
The numbers in this README come from files under artifacts/results/. Each file was written by a
script in scripts/ or by a GPU notebook. The evidence ledger near the top names the file behind
each number of the first screen. A file written by a simulation script records its date, the git
SHA (and whether the tree was dirty), the seed, the hardware, the installed package versions and
the hardware path. The raw files of GPU runs and most analysis files carry no commit id of their
own. For those, the last column of the ledger names the commit that last changed the file. The
history of this repository was rewritten on 27 November 2026. A commit id written inside a
results file made before that day belongs to the old history. Every
cost constant is in configs/cost_model.yaml, with a source URL and a date. If you disagree with a
constant, change it and run again to get your own number.
The rule: everything in artifacts/results/ must be reproducible by running a script in
scripts/. A result that cannot be deleted and made again does not go into the repository.
Two engines. The stored results come from the engine of release 0.2.0. The files that release
0.1.2 wrote and 0.2.0 changed are kept in artifacts/results/v0.1.2/, byte for byte. The old
engine is still in the code, for single runs and for the tests: run(..., engine_version="0.1.2"),
or with use_engine("0.1.2"): in the same process. The grid scripts start worker processes, and
from Python 3.14 on, and on macOS, those do not inherit it. To compute a grid of 0.1.2 again,
check out tag v0.1.2 or install release 0.1.2. The predictions that were registered before the
GPU runs were made with the old engine, and the tests check them with it.
One edit to stored outputs. In 13 stored files of the GPU runs (Phase 3, Phase 6, C1 to C4 and
V1), one path of vLLM's source tree is written entrypoints/.../serving.py, with a folder name left
out. It is a line of the notebooks' check of vLLM's source, not a measurement. In V1's two files it
is the only edit, and the analysis gives the same bytes with and without it.
One command checks it. python scripts/reproduce.py copies the files of the repository to a
temporary folder and runs twenty-one steps there. It compares every file a step writes with the
committed one. The steps cover the analysis of each GPU run (from the raw files it left here), the
grid behind the finding, the session cost table, the analyses made after results were seen, and
the evidence ledger. It takes about 13 minutes on a 12-thread laptop. --quick leaves out the
three slow steps and takes about a minute. Fields
that say when and where a file was made are left out of the comparison. Where the script makes one
more exception, it says so and says why. Not covered yet: the first two sweeps (Phase 4 and
Phase 5), H6, the scale test, the real-trace runs (R1 to R3, and the full-size run L1, whose traces
are downloaded and not committed), and the stored grids that some analyses start from (T2's three,
C4's, and those of calibrations B and C). A GPU measurement cannot be made again this way.
Sibling project
colpali-lite is not public yet. It uses the same method (cost and tail latency
under a configuration choice, bootstrap CIs, an explicit cost model, results in ₹ per unit of
useful work) for late-interaction retrieval instead of LLM serving. Serving cost is usually
measured too little in ML systems: mean latency only, no cost axis, no error bars.
License
MIT
Metadata
Release files for kv-routing-sim 0.2.0
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 |
|---|---|---|---|---|
| kv_routing_sim-0.2.0.tar.gz | 290.0 kB | Without provenance | Details for kv_routing_sim-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kv_routing_sim-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for kv_routing_sim-0.2.0-py3-none-any.whl |
Total release size: 440.1 kB
Release files / kv_routing_sim-0.2.0.tar.gz
| Download URL | kv_routing_sim-0.2.0.tar.gz |
|---|---|
| Size | 290.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f5a37831062908ec930aa27beb0f9a787914c4c880785b8568db026907a534a
|
|
BLAKE2b-256 checksum How to use checksums |
16ef6a2d83bd78abdf5e09d41246d3444e407b1526a4643aeb7f9cc3a4ab5503
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / kv_routing_sim-0.2.0-py3-none-any.whl
| Download URL | kv_routing_sim-0.2.0-py3-none-any.whl |
|---|---|
| Size | 150.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f62cd375977c40db653a9cb49609282c4da1b3181b2be437c1fa645fee78ae1d
|
|
BLAKE2b-256 checksum How to use checksums |
8d0f299cd4154d38bb2f64c9b02d9423c82f89890ce21d2df7af8ec637b486eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Security for kv-routing-sim 0.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.