How to find optimal value for GOGC?

103 views
Skip to first unread message

Christian LeMoussel

unread,
Nov 16, 2017, 12:26:06 PM11/16/17
to golang-nuts
Go has the GOGC variable, that can also be controlled with the SetGCPercent function in the runtime/debug package.
Is it possible to find the optimal value of GOGC to get the most op / s per report to the number of cores?



Ian Lance Taylor

unread,
Nov 16, 2017, 12:52:42 PM11/16/17
to Christian LeMoussel, golang-nuts
The default value is chosen to work well for most programs. That
said, if you want to look into this, it obviously depends on the
behavior of your program and the available resources. If your program
is a client that does not run for very long, then a very large GOGC
value is likely to be appropriate, to let the client run and exit
without spending unnecessary time collecting garbage. If your program
is a long running server, then it is going to reach some sort of
memory steady state. If you leave GOGC at the default value of 100,
then the memory steady state will be very approximately twice as much
memory as your program requires. If you have resources available to
let your program use more memory in the steady state, then adjust GOGC
accordingly. For example, if it's OK for your program to use twice as
much memory, set GOGC to 200.

Ian

Wojciech S. Czarnecki

unread,
Nov 17, 2017, 5:11:44 AM11/17/17
to golan...@googlegroups.com
Yes it is possible. Please read
https://blog.cloudflare.com/go-dont-collect-my-garbage/
for 'howto' tips.

Hope this helps,

--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE

Christian LeMoussel

unread,
Nov 17, 2017, 7:46:43 AM11/17/17
to golang-nuts
Interesting article. However, it does not describe the script/bench to find the best value, from 100 to 20,000, in increments of 100.
Reply all
Reply to author
Forward
0 new messages