Skip to content

Refactor SchedulerState to use per-handle waiter queues and a single FIFO queue #505

@coderabbitai

Description

@coderabbitai

Summary

The SchedulerState in src/client/pool/scheduler.rs currently uses three separate collections keyed by handle ID:

  • waiters: HashMap<u64, WaiterSender<…>>
  • fifo_waiters: VecDeque<u64>
  • round_robin_handles: VecDeque<u64>

This design requires keeping all three structures consistent and involves repeated retain scans in the round-robin and deregister paths, which adds maintenance burden and cross-collection consistency concerns.

Proposed improvement

Restructure SchedulerState to use per-handle waiter queues for round-robin and a single anonymous FIFO queue for FIFO policy. This would:

  • Eliminate the global waiters map and the fifo_waiters ID queue.
  • Remove retain scans from take_next_round_robin_waiter and deregister_handle.
  • Simplify the take_next_* selection logic by popping directly from per-handle queues.
  • Eliminate cross-collection consistency concerns entirely.

All existing behaviour would be preserved: FIFO policy retains strict arrival-order servicing, and round-robin policy continues to rotate fairly among registered handles.

Context

This was flagged as an architectural suggestion during the review of PR #498 (#498). The current implementation is correct and all tests pass; this is a follow-up refactoring opportunity to reduce complexity and improve maintainability.

Requested by @leynos.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions