Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Implement dynamically scaled Thread Pool #933

Merged
merged 2 commits into from
Sep 18, 2022
Merged

Conversation

Xaymar
Copy link
Owner

@Xaymar Xaymar commented Sep 18, 2022

Explain the Pull Request

While the previous approach of a static thread pool worked, it was sub-optimal in its resource usage. Many of the threads would never see a single task, and simply permanently sleep. This seems like a good idea, except that sleeping threads still end up in the scheduler, and thus waste a tiny amount of resources.

It is better to instead dynamically spawn threads when needed and only keeping the bare minimum around all the time. These dynamically spawned threads are also explicitly set to background priority which further reduces scheduling overhead. Finally optimizing the memory layout to prevent unwanted false sharing should also keep sporadic wake ups at a minimum.

This new model should be able to handle many more tasks than ever before, but is still not as optimal as it could be.

Completion Checklist

  • I have added myself to the Copyright and License headers and files.
  • I will maintain this code in the future and have added myself to CODEOWNERS.
  • I have tested this change on the following platforms:
    • MacOS 10.15
    • MacOS 11
    • MacOS 12
    • Ubuntu 20.04
    • Ubuntu 22.04
    • Windows 10
    • Windows 11

@Xaymar Xaymar force-pushed the patch/threadpooling branch 3 times, most recently from 1fb0ee6 to bd56d8c Compare September 18, 2022 16:35
@Xaymar Xaymar changed the title Patch/threadpooling Implement dynamically scaled Thread Pool Sep 18, 2022
@Xaymar Xaymar force-pushed the patch/threadpooling branch 4 times, most recently from e211feb to de0e791 Compare September 18, 2022 17:03
While the previous approach of a static thread pool worked, it was sub-optimal in its resource usage. Many of the threads would never see a single task, and simply permanently sleep. This seems like a good idea, except that sleeping threads still end up in the scheduler, and thus waste a tiny amount of resources.

It is better to instead dynamically spawn threads when needed and only keeping the bare minimum around all the time. These dynamically spawned threads are also explicitly set to background priority which further reduces scheduling overhead. Finally optimizing the memory layout to prevent unwanted false sharing should also keep sporadic wake ups at a minimum.

This new model should be able to handle many more tasks than ever before, but is still not as optimal as it could be.
@Xaymar Xaymar marked this pull request as ready for review September 18, 2022 17:11
@Xaymar Xaymar merged commit 75a025c into master Sep 18, 2022
@Xaymar Xaymar deleted the patch/threadpooling branch September 18, 2022 17:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant