feat: smart scheduling — adaptive polling, duration cache, weighted dispatch#41
Merged
pratyush618 merged 4 commits intomasterfrom Mar 22, 2026
Merged
feat: smart scheduling — adaptive polling, duration cache, weighted dispatch#41pratyush618 merged 4 commits intomasterfrom
pratyush618 merged 4 commits intomasterfrom
Conversation
Backpressure-aware polling: - Empty queue: exponential backoff (50ms → 100ms → ... → 1s max) - Job dispatched: resets to base interval immediately - Saves CPU on idle systems, faster response under load Per-task duration cache: - In-memory HashMap updated on every handle_result() - Tracks count + sum of wall_time_ns per task name - Foundation for queue aging and weighted dispatch - No DB queries needed — pure scheduler-side intelligence Also adds aging_factor config to SchedulerConfig (not yet wired to dequeue query — prepared for follow-up).
Adds weighted_least_loaded() that factors in avg task duration: score = in_flight * avg_duration_ns. A worker with 1 slow job scores higher than one with 3 fast jobs about to finish. Falls back to plain least_loaded when no duration data available.
Adaptive polling backed off to 1s on empty queues, causing periodic tasks to be picked up late. Now resets interval after check_periodic() runs, so newly enqueued periodic jobs are dispatched promptly.
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
Three scheduling intelligence improvements that build on Taskito's centralized Rust scheduler:
HashMap<task_name, (count, sum_ns)>updated on everyhandle_result(). Foundation for weighted dispatch and future queue aging.score = in_flight * avg_duration_ns. A worker with 1 slow job scores higher than one with 3 fast jobs finishing soon.Also adds
aging_factorfield toSchedulerConfig(prepared for follow-up queue aging feature).Test plan
cargo test --workspace— 48 tests pass (3 new dispatch tests)cargo checkall feature combos