The GOMAXPROCS Environment Variable
Explore the role of the GOMAXPROCS environment variable in Go programming, understanding how it sets the number of OS threads for concurrent execution. Learn to programmatically manage this setting and grasp the difference between concurrency and parallelism to optimize your Go applications.
We'll cover the following...
What is GOMAXPROCS?
The GOMAXPROCS environment variable allows us to set the number of OS threads (CPUs) that can execute user-level Go code simultaneously. Starting with Go version 1.5, the default value of GOMAXPROCS should be the number of logical cores available in our machine. There is also the runtime.GOMAXPROCS() function, which allows us to set and get the value of GOMAXPROCS programmatically.
If we decide to assign a value to GOMAXPROCS that is smaller than the number of cores in our machine, we might affect the performance of our program. However, using a GOMAXPROCS value that is larger than the number of available cores does not necessarily make our Go programs run faster.