feat!: implement priority aging and weighted fair scheduling#84
Merged
Conversation
…ase 1) Add dispatch-time priority aging that gradually promotes tasks waiting longer than a configurable grace period. Effective priority is computed in SQL (no write amplification) and capped at `max_effective_priority`. - New `AgingConfig` type with grace_period, aging_interval, max_effective_priority, and urgent_threshold - Modified peek_next/pop_next/pop_next_batch with aging ORDER BY clause - Schema: pause_duration_ms and paused_at_ms columns for clock freezing - All pause/resume paths accumulate pause_duration_ms correctly - Crash recovery accumulates stale pause duration - TaskEventHeader carries base_priority and effective_priority - SchedulerSnapshot exposes aging_config - Child tasks inherit parent's effective priority when aging enabled - SchedulerBuilder::priority_aging() for opt-in configuration - Zero overhead when aging is disabled (original query preserved)
…, phase 2) Add three-pass fair dispatch loop that allocates slots proportional to group weights, fills remaining capacity greedily, and dispatches urgently-aged tasks as a safety valve. Groups without explicit weights use the default weight; ungrouped tasks compete as a virtual group. New builder API: group_weight(), default_group_weight(), group_minimum_slots(). Runtime API: set_group_weight(), remove_group_weight(), reset_group_weights(), set_group_minimum_slots(). GroupWeightChanged event emitted on runtime changes. SchedulerSnapshot includes group_allocations. Store queries added: peek_next_in_group(), peek_next_ungrouped(), running/pending_counts_per_group(), peek_next_urgent(). Composes with phase 1 aging, rate limits, group pause, and concurrency caps. Fast dispatch disabled when weights configured.
Contributor
Benchmark ComparisonClick to expand |
- Add priority aging and weighted fair scheduling sections to priorities-and-preemption.md - Add AgingConfig, group weight, and fair scheduling builder methods to configuration.md - Add aging.rs, fair.rs, rate_limit.rs to module map and update dispatch cycle in design.md - Add glossary entries: effective priority, priority aging, group weight, fair scheduling, urgent threshold - Document GroupWeightChanged event, updated TaskEventHeader fields, and snapshot fields in progress-and-events.md - Add pause_duration_ms and paused_at_ms columns to schema docs in persistence-and-recovery.md - Update module starvation guidance in multi-module-apps.md to recommend aging and group weights - Update snapshot field listing in query-apis.md - Add priority aging and fair scheduling to lib.rs crate-level docs and feature list - Fix broken TaskEventHeader rustdoc link in task/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #37
New public API
priority_aging(AgingConfig)base_priority/effective_priorityonTaskEventHeadergroup_weight(group, weight)set_group_weight(group, weight)GroupWeightChangeddefault_group_weight(weight)remove_group_weight(group)group_minimum_slots(group, slots)reset_group_weights()set_group_minimum_slots(group, slots)New store queries
peek_next_in_group(),peek_next_ungrouped(),running_counts_per_group(),pending_counts_per_group(),peek_next_urgent()Schema changes (pre-1.0, inline)
pause_duration_ms INTEGER NOT NULL DEFAULT 0andpaused_at_ms INTEGER DEFAULT NULLadded totaskstable for aging clock management.