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

k8s 集群内部署的话直接用NumCPU()获取不到真实可用核心数 #313

Closed
ztelur opened this issue Dec 4, 2021 · 3 comments · Fixed by #340
Closed

k8s 集群内部署的话直接用NumCPU()获取不到真实可用核心数 #313

ztelur opened this issue Dec 4, 2021 · 3 comments · Fixed by #340
Assignees

Comments

@ztelur
Copy link
Contributor

ztelur commented Dec 4, 2021

https://github.com/apache/dubbo-go-pixiu/blob/develop/cmd/pixiu/pixiu.go#L151

这里是不是有点问题. 在 k8s 集群内部署的话直接用NumCPU()获取不到真实可用核心数. 会导致调度不合理延迟加大.

from others

@ztelur ztelur self-assigned this Dec 4, 2021
@AlexStocks
Copy link
Contributor

github.com/shirou/gopsutil v3

@ztelur
Copy link
Contributor Author

ztelur commented Dec 9, 2021

It seems that gopsutil doesn't work well in k8s too. stackoverflow answer recommand https://github.com/uber-go/automaxprocs.

import _ "go.uber.org/automaxprocs"

func main() {
  // Your application logic here.
}

pixiu code is like below

	if limitCpuNumber <= 0 {
		runtime.GOMAXPROCS(runtime.NumCPU())
	} else {
		runtime.GOMAXPROCS(int(limitCpuNumber))
	}

Do we need assign limitCpuNumber by command argument ?

@liu-song
Copy link

liu-song commented Dec 9, 2021

More recommended use go.uber.org/automaxprocs which automatically set GOMAXPROCS according to linux container quota。https://github.com/shirou/gopsutil/blob/master/cpu/cpu.go#L64 which returns the number of physical can't fix this. go.uber.org/automaxprocs has been used in dapr ,jaeger to fix the same bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants