Why is it recommended to set GOMAXPROCS higher than 1?

1,484 views
Skip to first unread message

Adam Renberg

unread,
Feb 2, 2015, 12:02:14 PM2/2/15
to consu...@googlegroups.com
When starting a consul agent I often see this in the logs:

==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1
==> Starting Consul agent...

Which is obviously because GOMAXPROCS is set to 1 (by the chef cookbook I use).

I apologize if this is simply Go-newbie ignorance, but what is the reason behind this recommendation? What can happen with GOMAXPROCS set to 1; how severe are the consequences? Should GOMAXPROCS be set to at least 2 on all types of machines, including those with only 1 core?

I've found a few hints of the underlying reason, but perhaps it could be clarified, both in the log message and in the documentation?


Best regards,
Adam

Michael Fischer

unread,
Feb 2, 2015, 12:09:18 PM2/2/15
to Adam Renberg, consu...@googlegroups.com
IMO it's bad advice unless (a) you actually have more than one CPU, or (b) the program requires more than one Go process to be fully concurrent.  If (b) is true, it should be noted somewhere.  (Also, not a Go expert, but isn't that evidence of bad design?  No insult intended...)

--Michael

--
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Armon Dadgar

unread,
Feb 2, 2015, 1:28:52 PM2/2/15
to consu...@googlegroups.com, Adam Renberg
Hey,

The reason we recommend setting GOMAXPROCS is to avoid potential
starvation of the scheduler. The Go runtime uses green threads (M:N). If
a single goroutine blocks the scheduler (via cgo for example) it can cause
degraded performance. Having another kernel thread available helps to
mitigate those issues.

Best Regards,
Armon Dadgar
Reply all
Reply to author
Forward
0 new messages