-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: GOMAXPROCS not working with cpu-bound goroutines #1492
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
Labels
Comments
Yeah, it looks like the garbage collector is holding things up. Here's a slightly more explicit example: package main import ( "os" "runtime" ) func main() { runtime.GOMAXPROCS(2) go func() { println("b0") _ = new(int) println("b1") os.Exit(0) }() println("a0") for { } } The one goroutine hangs at new(int) since the allocator is trying to do a garbage collection. It tries to stoptheworld which will hang since the other goroutine never enters the scheduler. Removing the new(int) allows the example to exit. |
Maybe, the amount of real time (note: not the CPU time) consumed by the stop-the-world action could be lowered by unmapping (the 'munmap' system call in Linux) the stacks of all OS threads except the stack of the OS thread (=X) which was the 1st one to enter the stop-the-world function. Ys=[all threads except X]. Since Ys will most likely try to use the stack in a very short time (for example, via the ESP register on i386), it will trigger a page fault in them. The sole purpose of these page faults is to "stop" Ys from thread X as soon as possible. Note: the "stop" is in parentheses because it could also be implemented by a C for-loop which is started as a consequence of making the page fault. I wonder what would be the actual performance of this in Linux. The GNU debugger (gdb) would be confused by this. Maybe, this can be partially solved by the Go program having a special boolean variable for controlling whether to use the current stop-the-world implementation or the page-faulting stop-the-world implementation. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: