-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Fix excess work stealing under low loads #2254
Merged
Merged
Conversation
This file contains 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
We perf tested this over at @WallarooLabs. It looks good. |
Theodus
approved these changes
Sep 29, 2017
jemc
reviewed
Sep 29, 2017
src/libponyrt/sched/cpu.c
Outdated
@@ -314,6 +314,10 @@ void ponyint_cpu_core_pause(uint64_t tsc, uint64_t tsc2, bool yield) | |||
// If it has been 1 billion cycles, pause 1 ms. | |||
ts.tv_nsec = 1000000; | |||
} | |||
else | |||
{ | |||
ts.tv_nsec = 100000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this line get a human-oriented comment above this line, like the preceding lines each have?
Fixes #1787 Interestingly, all the info needed to solve this issue a while ago was already in the issue but it wasn't until @slfritchie put his additional comments in #1787 (comment) that it all clicked for me. The excess CPU time is from us doing too much work stealing. In a normal scenario, with nothing to do, we'd not doing anything for a long time and we'd end up sleeping for quite a while. With the timer that goes off every few seconds as seen in the issue, that isn't what happens. We regularly get woken and end up in a work stealing cycle. Then, due to the lack of an `else` block for yielding, on OSX, we'd nanosleep for 0 which is the same as an immediate return. To see what the impact of that would be on any platform change the: ```c // 10m cycles is about 3ms if((tsc2 - tsc) < 10000000) return; ``` to ```c // 10m cycles is about 3ms if((tsc2 - tsc) < 1000000000) return; ``` This is effectively what we were running. That's a lot more work-stealing. And, not the increased CPU usage. The reason this was happening more on OSX is that on Linux, nanosleep 0 will sleep for at least a bit. Here we remove the variability and do a small nanosleep that will be the same across all platforms.
206b067
to
dd1e3ca
Compare
@jemc force pushed an update |
jemc
approved these changes
Sep 29, 2017
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.
Fixes #1787
Interestingly, all the info needed to solve this issue a while ago was
already in the issue but it wasn't until @slfritchie put his additional
comments in
#1787 (comment)
that it all clicked for me.
The excess CPU time is from us doing too much work stealing. In a normal
scenario, with nothing to do, we'd not doing anything for a long time
and we'd end up sleeping for quite a while.
With the timer that goes off every few seconds as seen in the issue,
that isn't what happens. We regularly get woken and end up in a work
stealing cycle.
Then, due to the lack of an
else
block for yielding, on OSX, we'dnanosleep for 0 which is the same as an immediate return. To see what
the impact of that would be on any platform change the:
to
This is effectively what we were running. That's a lot more
work-stealing. And, not the increased CPU usage. The reason this was
happening more on OSX is that on Linux, nanosleep 0 will sleep for at
least a bit. Here we remove the variability and do a small nanosleep
that will be the same across all platforms.