-
Notifications
You must be signed in to change notification settings - Fork 18k
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
runtime: scheduler: go-routine starvation #21053
Comments
This is #10958. Note that if you build with
This will be fixed when (if) |
@ALTree - Ah. Glad to see it work in progress. Shall I close this as dup? |
Yes, this is a dup. It's targeted to Go 1.10. |
@ALTree, does the
|
You can't just set the environment variable, IIRC. You have to set the variable and then rebuild the Go toolchain. |
Yeah you need to rebuild the toolchain from source with the variable enabled, e.g. |
@bradfitz, ah - thanks. Thought it was a runtime config. Rebuilding the toolchain now. |
What version of Go are you using (
go version
)?go version go1.8.3 windows/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
Consider the below program:
I was trying to get an estimate of the ops of atomics and mutexes. I wrote the above example. When instead of atomics, mutexes are used, it works as expected. However, when using atomics, when the number of go-routines are greater than the number of the actual physical threads on the system, the goroutine that's waiting on the timer (the main go-routine) is starved - I'm guessing is because of the CAS semantics of atomics that staves the runtime due to
SpinWait
s.What did you expect to see?
The program actually completes in a near a second.
What did you see instead?
The program never ends using 100% of the CPU.
This tells me that the scheduler ends up starving the goroutine that's waiting on the timer. Is it possible to improve the scheduler to detect this somehow and not end up starving? This is a unique problem due to the nature of go-routines. Coming from a .NET eco-system, where the
Task
units are run from a thread pool, which uses physical threads, the OS scheduler handles this smoothly, and this was quite a surprise to me - but makes sense considering the nature of go-routines.UPDATE
Surprisingly, looks like it doesn't actually have anything to do with atomics. Just turning it into an empty loop, causes the main go-routine to be starved. Quite confused on what to make of this. Is this some kind of a scheduler bug?
The text was updated successfully, but these errors were encountered: