Middle+
How many threads will the Go scheduler launch? Specifically on AMD EPYC with 64 cores and 128 threads?
sobes.tech AI
Answer from AI
The Go scheduler launches a number of threads equal to the value of the environment variable or the GOMAXPROCS parameter, which by default is set to the number of logical processors (CPU threads) on the machine.
On a system with AMD EPYC, having 64 physical cores and 128 threads (hyper-threading), the default GOMAXPROCS will be 128, meaning the Go scheduler will launch 128 OS threads to execute goroutines.
This means up to 128 goroutines can be executed simultaneously at the OS level, allowing efficient utilization of all logical processors. If necessary, GOMAXPROCS can be changed programmatically via runtime.GOMAXPROCS(n) or through the environment variable GOMAXPROCS.
Example of setting in code:
import "runtime"
func main() {
runtime.GOMAXPROCS(128) // explicitly set the number of threads
// ...
}