Number of threads used by Go runtime

There is no direct correlation. Threads used by your app may be less than, equal to or more than 10.

Quoting from the package doc of runtime:

The GOMAXPROCS variable limits the number of operating system threads that can execute user-level Go code simultaneously. There is no limit to the number of threads that can be blocked in system calls on behalf of Go code; those do not count against the GOMAXPROCS limit. This package’s GOMAXPROCS function queries and changes the limit.

So if your application does not start any new goroutines, threads count will be less than 10.

If your app starts many goroutines (>10) where none is blocking (e.g. in system calls), 10 operating system threads will execute your goroutines simultaneously.

If your app starts many goroutines where many (>10) are blocked in system calls, more than 10 OS threads will be spawned (but only at most 10 will be executing user-level Go code).

See this question for an example and details: Why does it not create many threads when many goroutines are blocked in writing file in golang?

Edit (in response to your edit):

I believe the default value of GOMAXPROCS is the number of logical CPUs for a reason: because in general that provides the highest performance. You may leave it at that. In general if you only have 1 goroutine and you’re sure your code doesn’t spawn more, GOMAXPROCS=1 is sufficient, but you should test and don’t take any word for it.

Leave a Comment