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
This commit is contained in:
Aliaksandr Valialkin 2022-04-06 13:32:01 +03:00
parent f082e64e0c
commit f526c7814e
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -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)
}
}