简体   繁体   中英

How to increase Go's GC CPU usage to more than 25%?

According to some articles (like this and this ), Go's garbage collector can only take up to 25% of available CPUs, and it seems that this number is actually the result of the golang developers hard work - they're trying to make this number rather small.

However, since in my case I want to run GC at specific timings (by runtime.GC() ) and I also want the GC finish as soon as possible, I wonder if it's possible to make Go's GC use up to, say, 100% of available CPUs, so that the GC finishes earlier.

Is this possible?

Context

My code has deterministic busy and idle times. Since the busy part should run very fast (it's too slow if GC is fired), I want to run GC within the idle times, which are also relatively short and so the GC should also run fast. I'm not going to non-GC languages because hard real-time isn't required and I'm not so smart to manage memory correctly.

I found it. If I set GODEBUG=gcstoptheworld=1 or GODEBUG=gcstoptheworld=2 , then the manual GC utilizes all the available CPUs, although this apparently disables concurrent GC. Ref: https://golang.org/pkg/runtime/

In my case this was enough. But I actually want to know how to utilize more CPUs when the concurrent GC works. It seems that simply increasing the values of gcGoalUtilization and gcBackgroundUtilization in runtime/mgc.go and buiding go from source does not work. Hmm...

EDIT

This definitely achieved better CPU utilizations, but in fact I could not see a noticeable speedup (according to go tool trace ). Maybe I'm missing something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM