mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 08:36:55 +03: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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user