mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/cgroup: round GOMAXPROCS to the lower integer value of cpuQuota
Rounding GOMAXPROCS to the upper interger value of cpuQuota increases chances of CPU starvation, non-optimimal goroutine scheduling and additional CPU overhead related to context switching. So it is better to round GOMAXPROCS to the lower integer value of cpuQuota.
This commit is contained in:
parent
2a17cddf3d
commit
dba0553e11
1 changed files with 9 additions and 4 deletions
|
@ -37,15 +37,20 @@ func updateGOMAXPROCSToCPUQuota(cpuQuota float64) {
|
|||
// Do not override explicitly set GOMAXPROCS.
|
||||
return
|
||||
}
|
||||
gomaxprocs := int(cpuQuota + 0.5)
|
||||
|
||||
// Round gomaxprocs to the floor of cpuQuota, since Go runtime doesn't work well
|
||||
// with fractional available CPU cores.
|
||||
gomaxprocs := int(cpuQuota)
|
||||
if gomaxprocs <= 0 {
|
||||
gomaxprocs = 1
|
||||
}
|
||||
|
||||
numCPU := runtime.NumCPU()
|
||||
if gomaxprocs > numCPU {
|
||||
// There is no sense in setting more GOMAXPROCS than the number of available CPU cores.
|
||||
gomaxprocs = numCPU
|
||||
}
|
||||
if gomaxprocs <= 0 {
|
||||
gomaxprocs = 1
|
||||
}
|
||||
|
||||
runtime.GOMAXPROCS(gomaxprocs)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue