VictoriaMetrics/lib/cgroup/util.go
Aliaksandr Valialkin 6721e47ae9 app: respect CPU limits set via cgroups
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
2020-08-11 23:01:03 +03:00

25 lines
671 B
Go

package cgroup
import (
"bytes"
"io/ioutil"
"os/exec"
"strconv"
)
func readInt64(path, altCommand string) (int64, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
// Read data 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 data location inside lxc container.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/84
cmd := exec.Command("/bin/sh", "-c", altCommand)
data, err = cmd.Output()
if err != nil {
return 0, err
}
}
data = bytes.TrimSpace(data)
return strconv.ParseInt(string(data), 10, 64)
}