mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-16 00:41:24 +01:00
6721e47ae9
Update GOMAXPROCS to limits set via cgroups. This should reduce CPU trashing and reduce memory usage for cases when VictoriaMetrics components run in containers with CPU limits. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/685
17 lines
758 B
Go
17 lines
758 B
Go
package cgroup
|
|
|
|
// GetMemoryLimit returns cgroup memory limit
|
|
func GetMemoryLimit() int64 {
|
|
// Try determining the amount of memory inside docker container.
|
|
// See https://stackoverflow.com/questions/42187085/check-mem-limit-within-a-docker-container
|
|
//
|
|
// Read memory limit according to https://unix.stackexchange.com/questions/242718/how-to-find-out-how-much-memory-lxc-container-is-allowed-to-consume
|
|
// This should properly determine the limit inside lxc container.
|
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/84
|
|
n, err := readInt64("/sys/fs/cgroup/memory/memory.limit_in_bytes", "cat /sys/fs/cgroup/memory$(cat /proc/self/cgroup | grep memory | cut -d: -f3)/memory.limit_in_bytes")
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
return n
|
|
}
|