mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/cgroup: limit the maximum GOMAXPROCS value to the number of available CPU cores
There is no sense in setting GOMAXPROCS to value higher than the number of available CPU cores.
This commit is contained in:
parent
10601bc652
commit
f4c4ab811b
1 changed files with 8 additions and 0 deletions
|
@ -12,6 +12,8 @@ import (
|
|||
// This function must be called after logger.Init().
|
||||
func UpdateGOMAXPROCSToCPUQuota() {
|
||||
if v := os.Getenv("GOMAXPROCS"); v != "" {
|
||||
// Do not override explicitly set GOMAXPROCS.
|
||||
logger.Infof("using GOMAXPROCS=%q set via environment variable", v)
|
||||
return
|
||||
}
|
||||
q := getCPUQuota()
|
||||
|
@ -20,6 +22,12 @@ func UpdateGOMAXPROCSToCPUQuota() {
|
|||
return
|
||||
}
|
||||
gomaxprocs := int(q + 0.5)
|
||||
numCPU := runtime.NumCPU()
|
||||
if gomaxprocs > numCPU {
|
||||
// There is no sense in setting more GOMAXPROCS than the number of available CPU cores.
|
||||
logger.Infof("cgroup CPU quota=%d exceeds NumCPU=%d; using GOMAXPROCS=NumCPU", gomaxprocs, numCPU)
|
||||
return
|
||||
}
|
||||
if gomaxprocs <= 0 {
|
||||
gomaxprocs = 1
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue