Skip to content

perf(kv-router): index selection reservations by partition - #11

Closed
ishandhanani wants to merge 1 commit into
idhanani/p0-selection-lora-filterfrom
idhanani/p0-selection-reservation-index
Closed

ishandhanani wants to merge 1 commit into
idhanani/p0-selection-lora-filterfrom
idhanani/p0-selection-reservation-index

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Phase 0 (selection-core parity), item 3. Stacked on #10.

Summary

prefill_complete, free_reservation, and add_output_block (core/mod.rs:1043-1098 on main) walked every partition scheduler per call because a selection id carries no partition. That is a per-request cost that scales with partitions, which Phase 3 doubles (two embedded services) and extends (encoder/fallback pools).

  • New reservation_index: RwLock<HashMap<String, RoutingPartitionId>> on SelectionCore (standard hasher: ids are caller-controlled, per lib/kv-router/AGENTS.md). Populated by both booking paths: schedule_selection when book == true and finalize_reservation.
  • lifecycle_entries(id) returns the indexed partition first, then the rest, so the existing full-scan fallback still covers bookings mirrored from replica peers (which never pass through this core's booking paths).
  • Removal: on free, on a NotFound that exhausted every partition, and by a periodic sweep (period = active_request_expiry_duration()) that drops ids whose booking the scheduler no longer holds (force-expiry). The sweep is spawned lazily from the first ensure_entry so new_local still works without a runtime.
  • LocalScheduler::has_request(&str) -> bool added for the sweep.

Validation

  • cargo test -p dynamo-kv-router --features standalone-selection --lib: 1055 passed. New: reservation_index_tracks_bookings_until_freed (both booking paths, indexed-first ordering, free/NotFound removal) and reservation_index_sweep_drops_bookings_released_out_of_band (release straight through the scheduler, sweep removes exactly that id). lifecycle_operations_find_reservation_in_later_entry still passes (fallback path).
  • cargo clippy --features standalone-selection --all-targets: only the pre-existing registry.rs dead-code warning. cargo fmt clean.

prefill_complete, free_reservation, and add_output_block arrive with only a
selection id, so SelectionCore scanned every partition scheduler on each call.
With two embedded services (prefill + decode pools) and encoder/fallback
partitions this becomes a per-request O(partitions) walk on the lifecycle
path.

Add a selection_id -> RoutingPartitionId index populated by both booking paths
(select_and_reserve and create_reservation). Lifecycle calls try the indexed
partition first and fall back to the full scan, which keeps bookings mirrored
from replica peers working. Entries are removed on free, on a NotFound that
exhausts every partition, and by a periodic sweep that drops ids whose booking
was released out of band (force-expiry). The sweep task starts lazily from the
first ensure_entry so construction does not require a runtime.

Adds LocalScheduler::has_request for the sweep.

Tests: index population by both paths, indexed-first ordering, removal on
free/NotFound, and sweep of an out-of-band release. Existing later-entry
fallback test unchanged.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani

Copy link
Copy Markdown
Owner Author

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

This branch had an error being deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant