Skip to content

feat: smart scheduling — adaptive polling, duration cache, weighted dispatch#41

Merged
pratyush618 merged 4 commits intomasterfrom
feat/smart-scheduling
Mar 22, 2026
Merged

feat: smart scheduling — adaptive polling, duration cache, weighted dispatch#41
pratyush618 merged 4 commits intomasterfrom
feat/smart-scheduling

Conversation

@pratyush618
Copy link
Copy Markdown
Collaborator

Summary

Three scheduling intelligence improvements that build on Taskito's centralized Rust scheduler:

  • Adaptive backpressure-aware polling: scheduler poll interval now adapts to workload — backs off exponentially (50ms → 1s) when queue is empty, resets instantly when a job is found. Saves CPU on idle systems.
  • Per-task duration cache: in-memory HashMap<task_name, (count, sum_ns)> updated on every handle_result(). Foundation for weighted dispatch and future queue aging.
  • Weighted least-loaded dispatch: prefork pool can now factor in avg task duration — 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_factor field to SchedulerConfig (prepared for follow-up queue aging feature).

Test plan

  • cargo test --workspace — 48 tests pass (3 new dispatch tests)
  • cargo check all feature combos
  • All existing scheduler tests pass with new return type

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.
@pratyush618 pratyush618 merged commit 882d345 into master Mar 22, 2026
10 checks passed
@pratyush618 pratyush618 deleted the feat/smart-scheduling branch March 31, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant