Skip to content

feat(task): add App::task_pool_keep_threads and tidy retiring workers - #3307

Merged
Hona merged 1 commit into
devfrom
feat/task-pool-keep-threads
Dec 2, 2026
Merged

Hona merged 1 commit into
devfrom
feat/task-pool-keep-threads

Conversation

@Hona

@Hona Hona commented Dec 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Add process-wide builder App::task_pool_keep_threads(usize) (default 2, ignored on wasm32) to control how many idle native rune-task workers stay alive between bursts. Passing 0 lets every worker retire 10 seconds after its last task and starts a new worker on demand for subsequent tasks.
  • Retiring task-pool workers now run task::on_idle on exit whenever they ran work since their last tidy, whether or not the periodic tidy timer (IDLE / IDLE_MIN_GAP) was due.
  • Anchor each worker's 10-second linger deadline to its last completed task instead of its last wake, so spurious wakes, notifies consumed by another worker, and task_pool_keep_threads updates never restart a full linger.
  • Refactor rune_core::task::pool around a testable Pool with a tidy-hook seam and add focused unit tests covering zero-keep drain/reuse, scale-up/scale-down floor retention, tidy-on-exit (with keep = 1, keep = 0, already-tidied, and IDLE_MIN_GAP cases), linger anchoring across wakes, Tidy transitions, and App::task_pool_keep_threads.

Verification

  • cargo test -j 1 -p rune-core --lib task::pool (7 passed)
  • cargo clippy -j 1 -p rune-core --lib --tests --no-deps
  • cargo test -j 1 -p rune --lib app::tests::task_pool_keep_threads (1 passed)
  • cargo clippy -j 1 -p rune --lib --tests --no-deps
  • cargo check -j 1 -p rune --target wasm32-unknown-unknown
  • scripts/file-size.sh (0 errors, 0 folder-shape issues)

Fixes #3294

Add App::task_pool_keep_threads(usize) (default 2, ignored on web) so
apps can choose how many idle rune-task workers stay alive between
bursts (0 lets every worker retire 10 seconds after its last task and
respawn on demand).

Also update native task-pool workers at every keep count to:
- run task::on_idle on exit whenever work ran since their last tidy,
  even if the periodic tidy timer was not yet due
- count the 10-second linger from each worker's last task rather than
  from its last wake (spurious wakes, stolen notifies, or keep changes)

Fixes #3294
Copilot AI balanced review requested due to automatic review settings December 2, 2026 14:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Hona
Hona merged commit a063e1d into dev Dec 2, 2026
7 checks passed
@Hona
Hona deleted the feat/task-pool-keep-threads branch December 2, 2026 14:54
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.

Let the app choose how many idle task-pool threads stay

2 participants