Make dynamic scheduler scaling more robust and configurable #2801
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.
Prior to this commit, dynamic scheduler scaling was not quite as
robust as we might like. When it came to waking sleeping threads,
the logic would send multiple wake signals in the hope that one
of them would work successfully and wake any sleeping thread that
might still be asleep. It was possible that even with sending
multiple signals, they could all be missed resulting in a thread
staying suspended when it should be awake.
This commit changes the logic to add a "check variable" that is
updated by threads after they wake up. This "check variable"
(
active_scheduler_count_check
) is a mirror of the currentactive_scheduler_count
and is used to confirm that a sleepingthread has successfully woken up. This commit also changes the
logic to ensure that when threads are being woken up, they are
only sent a single signal (to minimize unnecessary work). If that
signal is missed, then scheduler thread 0 would notice that
active_scheduler_count != active_scheduler_count_check
and sendanother signal until the thread wakes up and updates the check
variable. This should ensure that it is not possible to have a
hanging thread due to missed signals. Overall, these changes
should make dynamic scheduler scaling more robust, including
allowing for scheduler thread 0 to also suspend. (Scheduler
thread 0 suspension is experimental because @slfritchie ran into
an issue related to programs hanging when using network IO and
suspending scheduler thread 0 a few months ago. This commit
should in theory resolve this due to the "check variable" but I
haven't had an opportunity to test and confirm whether it
actually does so or not.)
This commit also adds in a new command line option for dynamic
configutation of the threshold after which a thread is allowed to
suspend (and also separates it from the scheduler block threshold.
This new option is called
--ponysuspendthreshold
. This optionis needed because the current suspend threshold (about 1 ms) is
very aggresive and @slfritchie noted that scheduler threads
suspend and don't wake up even under high network load. This
option allows for the threshold to be increased (or decreased)
on a per application run time basis. Additionally, it likely
makes sense to change the default to be something more
"appropriate and balanced" based on some sort of fancy
heuristics/tests done with different values for the threshold.