Skip to content

feat(router): re-host KvRouter scheduling on an embedded selection partition - #18

Closed
ishandhanani wants to merge 1 commit into
idhanani/p0-selection-router-hintfrom
idhanani/p1-kv-router-embedded-selection
Closed

ishandhanani wants to merge 1 commit into
idhanani/p0-selection-router-hintfrom
idhanani/p1-kv-router-embedded-selection

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Phase 1 of the runtime-optional frontend roadmap (1a: scheduler + active-sequence accounting re-hosted; the indexer stays on the router for now). Stacked on #16.

Summary

Behind KvRouterConfig::router_embedded_selection (--router-embedded-selection / DYN_ROUTER_EMBEDDED_SELECTION, default off), the frontend KvRouter runs scheduling and active-sequence accounting on one partition of an in-process SelectionService (the same core as the standalone selection service) instead of the runtime-bound KvScheduler.

  • RouterScheduler enum in KvRouter dispatches statically to either backend; all 17 scheduler call sites go through it. Request leases fence with the partition scheduler's booking_cleanup exactly as before.
  • kv_router/embedded.rs: builds the service with the registry-resolved policy (or Dynamo's default scorer/picker under the router's metric label, matching DefaultWorkerSelector::new(config, metric_worker_type)), the router's overload/availability providers and prefill estimator as host hooks, and the router's own indexer as the dequeue-time overlap refresh source. A catalog feeder mirrors the runtime-config watch into the partition's worker catalog (dp layout, capacities, taints, topology, KV-transfer, router-hint metadata).
  • The router keeps its indexer and request transport: it computes overlap against its indexer and hands the partition a fully formed ScheduleRequest.
  • Selection-service additions: SelectionPartition handle, ensure_partition (scheduler exists before workers register), external_kv_events (host feeds KV state; no ZMQ listeners), builder policy-factory override, OverlapRefreshSource (partition indexer / external / disabled).
  • Plumbing: PyO3 KvRouterConfig(router_embedded_selection=), .pyi, Python arg group + CLI flag, frontend-configuration.mdx.
  • Not carried over in embedded mode (documented): NATS active-sequence replica sync (warns), per-class queue metrics, scheduler-load publication to the routing-load monitor.

Validation

  • cargo test -p dynamo-llm --lib -- kv_router: 332 passed (runtime path unchanged). New routing_host::embedded_selection_books_and_releases_like_the_runtime_scheduler mirrors the runtime preview/plan/abort/track/free flow on the embedded path; embedded::worker_request_mirrors_runtime_config covers the catalog mapping.
  • cargo test -p dynamo-kv-router --features standalone-selection --lib: 1069 passed. Clippy clean on both crates (pre-existing registry.rs warning only). pytest components/.../test_kv_router_args.py: 63 passed. maturin develop --release builds; KvRouterConfig(router_embedded_selection=True) accepted.

Benchmark gate (dynamo-frontend-benchmark, mock workers)

dynamo.frontend --router-mode kv pinned to cores 0-3, 4 dynamo.mocker workers + aiperf on cores 4-15, block size 64, Qwen3-0.6B tokenizer, aiperf closed loop concurrency 128, 1024 requests after 256 warmup, arms interleaved, teardown between runs (DYN_ROUTER_EMBEDDED_SELECTION=1 for the embedded arm; confirmed via the frontend log marker each run).

arm iter req/s latency p50 / p99 (ms) TTFT p50 / p99 (ms)
runtime 1 133.0 595 / 1396 244 / 722
runtime 2 137.2 549 / 1451 220 / 1048
runtime 3 138.7 510 / 1393 224 / 762
embedded 1 146.9 509 / 1122 217 / 803
embedded 2 145.2 475 / 1227 162 / 649
embedded 3 145.9 484 / 1075 151 / 876

Medians: embedded 145.9 req/s vs runtime 137.2 (+6.3%); p50 latency 484 vs 549 ms; p99 1122 vs 1396 ms. No routing-quality or latency regression; the embedded partition is slightly faster (no NATS sequence publisher on the booking path). All 1024 requests completed in every run; no frontend errors or panics. The KV replay-parity campaign and tests/router e2e on both paths remain to run before deleting the old wiring (exit gate for removing KvScheduler).

…rtition

Phase 1a of the runtime-optional frontend roadmap. Behind
KvRouterConfig::router_embedded_selection (--router-embedded-selection /
DYN_ROUTER_EMBEDDED_SELECTION, default off), the frontend KvRouter runs its
scheduling and active-sequence accounting on one partition of an in-process
SelectionService instead of the runtime-bound KvScheduler:

- RouterScheduler enum in KvRouter dispatches statically to either backend;
  every router method (admitted and advisory scheduling, bookings, lifecycle,
  potential loads) goes through it. Request leases fence with the partition
  scheduler's booking_cleanup exactly as with KvScheduler.
- kv_router/embedded.rs builds the service with the registry-resolved policy
  (or Dynamo's default scorer/picker under the router's metric label), the
  router's overload/availability providers and prefill estimator as host
  hooks, and the router's own indexer as the dequeue-time overlap refresh
  source. A catalog feeder mirrors the runtime-config watch into the
  partition's worker catalog (dp layout, capacities, taints, topology,
  KV-transfer, router-hint metadata).
- The router keeps its indexer and request transport: it computes overlap
  against its indexer and hands the partition a fully formed ScheduleRequest.

Selection-service additions used by the host: SelectionPartition handle,
ensure_partition (create the scheduler before workers register),
external_kv_events (host feeds KV state; no ZMQ listeners), a policy-factory
override on the builder, and OverlapRefreshSource (partition indexer,
external, or disabled).

Not carried over in embedded mode: NATS active-sequence replica sync
(router_replica_sync warns), per-class queue metrics, and scheduler load
publication to the routing-load monitor.

Tests: routing_host::embedded_selection_books_and_releases_like_the_runtime_scheduler
mirrors the runtime preview/plan/abort/track/free flow on the embedded path;
embedded::worker_request_mirrors_runtime_config covers the catalog mapping.
All existing kv_router tests pass on the runtime path.

Signed-off-by: Ishan Dhanani <[email protected]>
@github-actions github-actions Bot added feat documentation Improvements or additions to documentation router labels Sep 3, 2026
@ishandhanani

Copy link
Copy Markdown
Owner Author

Superseded by the upstream-shaped staging stack: continued as #47 (rebased onto ai-dynamo/main, see #33).

This branch had an error being deployed

1 failed deployment
external_collaborator — fac22663 Deployed Sep 3, 2026 by ishandhanani via ok-to-test #32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feat router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant