From 077193d87caac981c78a528bd3ac2c95b0ff0620 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 6 Apr 2022 13:32:01 +0300 Subject: [PATCH] lib/cgroup: reduce the default GOGC value from 50% to 30% This reduces memory usage under production workloads by up to 10%, while CPU spent on GC remains roughly the same. The CPU spent on GC can be monitored with go_memstats_gc_cpu_fraction metric --- lib/cgroup/mem.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/cgroup/mem.go b/lib/cgroup/mem.go index 2fa34a11a..f35d3cbad 100644 --- a/lib/cgroup/mem.go +++ b/lib/cgroup/mem.go @@ -19,15 +19,17 @@ func init() { func initGOGC() { if v := os.Getenv("GOGC"); v != "" { - n, err := strconv.Atoi(v) + n, err := strconv.ParseFloat(v, 64) if err != nil { n = 100 } - gogc = n + gogc = int(n) } else { - // Set GOGC to 50% by default if it isn't set yet. - // This should reduce memory usage for typical workloads for VictoriaMetrics components. - gogc = 50 + // Use lower GOGC if it isn't set yet. + // This should reduce memory usage for typical workloads for VictoriaMetrics components + // at the cost of increased CPU usage. + // It is recommended increasing GOGC if go_memstats_gc_cpu_fraction exceeds 0.05 for extended periods of time. + gogc = 30 debug.SetGCPercent(gogc) } }