Take into account the number of available threads before posting work to the thread pool - #23
Merged
Conversation
Otherwise we risk having all jobs in memory waiting for available threads, that will be lost if the worker is shutdown, and will be left claimed in limbo.
To prevent sleeping for the whole polling interval if there are jobs waiting but there weren't any available threads to take them.
rosa
force-pushed
the
check-available-threads
branch
from
August 10, 2023 16:57
84b4318 to
3430c0c
Compare
hms
pushed a commit
to ikyn-inc/solid_queue
that referenced
this pull request
Aug 5, 2024
Implement a solid queue adapter
Merged
2 tasks
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.
Before this PR, we'd just post all available jobs to the pool regardless of whether there were threads available
Otherwise, we risk having all jobs in memory waiting for available threads. Then, if the worker is shutdown, these would be left unclaimed in limbo until manually released.
This made a new scenario possible: if we have many fast jobs available, we'd be sleeping for the whole polling interval waiting for threads to be available, even if the jobs are very fast, and that happens way before the polling interval is over. To avoid this, we allow the pool to wake up the worker when new threads become available.