> The CPU profiler told me that the program is spending a lot of time doing GC (obviously), and memory profiler is telling me there is a huge amount of memory allocated for json encoding/decoding, which is inevitable for business logic.
Even though Go is GC based language, Go prefers object re-using to prevent extra allocations as much as possible. Check if there are parts of the codebase that allocates a lot on the hot path, and if object pooling, preallocations, etc, might be applied there. You may start by switching to alternative json marshallers – mailru/easyjson or json-iterator – if this is your case. They were developed to handle these particular issues of Go's encoding/json. On Tuesday, February 6, 2018 at 3:45:56 PM UTC+1, Bob Cao wrote: > > Hi Lan > > I have used memory profiler and CPU profiler. > > The CPU profiler told me that the program is spending a lot of time doing > GC (obviously), and memory profiler is telling me there is a huge amount of > memory allocated for json encoding/decoding, which is inevitable for > business logic. > > And the issue is, it used to be fine. The codebase has been in production > for a long time and the average GC per minute used to around 30 per minute, > and very stable. > > Is there any tip on how should one solve such problems? > > Thanks a lot! > > On Tuesday, 6 February 2018 22:40:07 UTC+8, Ian Lance Taylor wrote: >> >> On Tue, Feb 6, 2018 at 12:58 AM, Bob Cao <bobint...@gmail.com> wrote: >> > >> > I have a program whose GC pause frequency will quickly go from 40 calls >> per >> > minute to 2000 calls per minute in a matter of hours, and the issue is >> kind >> > of random on production. >> > >> > Is there any advice on how to spot the cause of the issue? >> >> Use the memory profiler. See >> https://blog.golang.org/profiling-go-programs for some background. >> >> Ian >> > -- 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. For more options, visit https://groups.google.com/d/optout.