Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement work stealing #373

Merged
merged 7 commits into from
Apr 28, 2023
Merged

Implement work stealing #373

merged 7 commits into from
Apr 28, 2023

Conversation

jpsamaroo
Copy link
Member

@jpsamaroo jpsamaroo commented Feb 25, 2023

Adds logic to do work stealing within and across workers, which can help prevent workload imbalance and processor starvation.

Todo:

  • Consider a non-racy implementation of Sch.Doorbell (Base.Event)
  • Add tests Existing tests should be sufficient
  • Add docs

The worker scheduler would previously assume that it was fine to
schedule infinite amounts of work onto the same processor at once, which
is only efficient when tasks do lots of `yield`ing. Because most tasks
do not actually exhibit low occupancy, we want to teach at least the
worker scheduler to limit its eagerness when executing high-occupancy
tasks.

This commit teaches `@spawn` and the worker scheduler about a new
`occupancy` task option, which (on the user side) is a value between 0
and 1 which approximates how fully the task occupies the processor. If
the occupancy is 0.2, then 5 such tasks can execute concurrently and
fully occupy the processor.

Processors now operate primarily from a single controlling task per
processor, and work is executed in a lowest-occupancy-first manner to
attempt to maximize throughput.

With processors using occupancy estimates to limit oversubscription,
it's now quite easy for tasks to become starved for work. This commit
also adds work-stealing logic to each processor, allowing a starved
processor to steal scope-compatible tasks from other busy processors.
Processors will be able to steal so long as they are not fully occupied.
@jpsamaroo jpsamaroo merged commit 4b83c4b into master Apr 28, 2023
@jpsamaroo jpsamaroo deleted the jps/task-balance branch April 28, 2023 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant