You really can't.
You control CPU usage by the GC by allocation rate, the number of live objects, and the collection rate. If you slow the collector (lower CPU), you will have higher memory usage because the GC won't have time to collect the garbage.
In general, the only things you are in control of are 1) how many objects you allocate, 2) the size of these objects, 3) how often do you allocate them, and 4) how long you keep them around (keep references).
There is always a trade-off between CPU usage (by GC) and memory usage.
The truth though is that you pay similar costs even if you manage the memory yourself, and typically requires a lot more error prone code to do so.
-----Original Message-----
From: Joseph Wang
Sent: Jun 4, 2019 2:16 AM
To: golang-nuts
Subject: [go-nuts] How can I debug high garbage collection rate cause high CPU usage issue in golangHello everyone--I just have a question about my golang code debugging. It's not specific code question. But I never met this issue before.The problem is like this. I replaced our back-end system's cache from single node cache to groupcache that is a kind mem cache. Then I met high memory usage issue at beginning. I use pprof and online resource then I set up GC rate(10%) to reduce memory usage down to normal. But then this will cause high CPU usage, because heavy GC operations. I use pprof to get the hot spot is runtime.ScanObject() this function, which is out of scope of my code base.So I don't know if anyone can give me some suggestions about how to fix this kind issue. I know the issue should come from my code base. But I don't know how to find out the issue and fix it ASAP.Best,Joseph
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5c977af4-074e-4eaf-85c2-2a284595b572%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/882629733.1993.1559656354509%40wamui-fatboy.atl.sa.earthlink.net.
For more options, visit https://groups.google.com/d/optout.