From fd0c0e3f00498b0272243cd64ffdc70218e82f0a Mon Sep 17 00:00:00 2001 From: jiangxy Date: Sun, 8 Jan 2023 14:37:06 +0800 Subject: [PATCH 1/3] perf: get cgroup cpu core --- holmes.go | 17 +++++++++++++---- util.go | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/holmes.go b/holmes.go index 2e7d635..2dcdf44 100644 --- a/holmes.go +++ b/holmes.go @@ -703,12 +703,21 @@ func (h *Holmes) getCPUCore() (float64, error) { 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, CPU core: %v, error: %v", cpuCore, err) + } + if cpuCore > 0 { + return cpuCore, nil + } } - if h.opts.UseCGroup { - return getCGroupCPUCore() + // Support to be used together with UseCGroup, and CGroup has higher priority + if h.opts.UseGoProcAsCPUCore { + return float64(runtime.GOMAXPROCS(-1)), nil } return float64(runtime.NumCPU()), nil diff --git a/util.go b/util.go index 4ad8bb4..61ae310 100644 --- a/util.go +++ b/util.go @@ -118,6 +118,7 @@ func getCGroupCPUCore() (float64, error) { return 0, err } + // No resource limit value is configured, the value is -1 if cpuQuota, err = readUint(cgroupCpuQuotaPath); err != nil { return 0, err } From 70ef4156db139ad500e460ad434f79733ef96b5f Mon Sep 17 00:00:00 2001 From: jiangxy Date: Wed, 11 Jan 2023 10:33:45 +0800 Subject: [PATCH 2/3] fix: comments --- holmes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/holmes.go b/holmes.go index 2dcdf44..eb827ed 100644 --- a/holmes.go +++ b/holmes.go @@ -698,6 +698,7 @@ 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 @@ -708,14 +709,13 @@ func (h *Holmes) getCPUCore() (float64, error) { // 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, CPU core: %v, error: %v", cpuCore, err) + h.Warnf("[Holmes] get CGroup CPU core failed, will try to obtain cpu in other ways. CPU core: %v, error: %v", cpuCore, err) } if cpuCore > 0 { return cpuCore, nil } } - // Support to be used together with UseCGroup, and CGroup has higher priority if h.opts.UseGoProcAsCPUCore { return float64(runtime.GOMAXPROCS(-1)), nil } From cb11cf84c07e822259c4d6ebba172e0ac147f21a Mon Sep 17 00:00:00 2001 From: jiangxy Date: Wed, 11 Jan 2023 14:15:13 +0800 Subject: [PATCH 3/3] fix: warn log --- holmes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holmes.go b/holmes.go index eb827ed..57c7135 100644 --- a/holmes.go +++ b/holmes.go @@ -709,7 +709,7 @@ func (h *Holmes) getCPUCore() (float64, error) { // 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. CPU core: %v, error: %v", cpuCore, err) + 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