Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions holmes.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,17 +698,26 @@ func (h *Holmes) gcHeapCheckAndDump() {
}
}

// Support `UseGoProcAsCPUCore` to be used together with `UseCGroup`, and `UseCGroup` has higher priority.
func (h *Holmes) getCPUCore() (float64, error) {
if h.opts.cpuCore > 0 {
return h.opts.cpuCore, nil
}

if h.opts.UseGoProcAsCPUCore {
return float64(runtime.GOMAXPROCS(-1)), nil
if h.opts.UseCGroup {
// If executed get cpuCore equal to 0 (most likely because no resource limit is set),
// Then only print out err, and finally return the number of CPU logic cores compatible.
cpuCore, err := getCGroupCPUCore()
if err != nil {
h.Warnf("[Holmes] get CGroup CPU core failed, will try to obtain cpu in other ways. error: %v", err)
}
if cpuCore > 0 {
return cpuCore, nil
}
}

if h.opts.UseCGroup {
return getCGroupCPUCore()
if h.opts.UseGoProcAsCPUCore {
return float64(runtime.GOMAXPROCS(-1)), nil
}

return float64(runtime.NumCPU()), nil
Expand Down
1 change: 1 addition & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func getCGroupCPUCore() (float64, error) {
return 0, err
}

// No resource limit value is configured, the value is -1
Comment thread
istudies marked this conversation as resolved.
if cpuQuota, err = readUint(cgroupCpuQuotaPath); err != nil {
return 0, err
}
Expand Down