Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: get cgroup cpu core #137

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
istudies marked this conversation as resolved.
Show resolved Hide resolved
if cpuQuota, err = readUint(cgroupCpuQuotaPath); err != nil {
return 0, err
}
Expand Down