Investigate if joining meaningfully reduces CPU #3447
Draft
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.
Description
The whole-host profiler on one of our benchmarks regularly shows an unusually large amount of CPU spent in shutdown:
As you can see, most of it is spent in
sched_yield
. It's not surprising that this burns CPU (it's roughly what we're asking it to do, spin-loop and wait for the other thread to finish), but what is surprising is that this chunk accounts for roughly 1/3 of all time spent in the profiler in the benchmark.Perhaps this basically says that our CPU overhead is very low, and that on shutdown we have to wait a few hundred milliseconds for another thread to complete. Waiting for that thread is dominating our time spent.
But I wanted to see what the profiles would look like if I ran this with a traditional thread join. We busy-wait because of an obscure bug we never were able to reproduce.
Results
The version with the commit hash behind it is the branch that uses
join
instead. As you can see, it does reduce the CPU a bit. I looked at the profiles from the whole-host profiler andshutdown
wasn't present at all.So yes, confirmed that it lowers the CPU. It's not particularly meaningful to use less CPU during shutdown, though.
Reviewer checklist