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

Update GOMAXPROCS configuration #4016

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
3 changes: 0 additions & 3 deletions cmd/spiderpool-agent/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ var envInfo = []envConf{
{"GIT_COMMIT_VERSION", "", false, &agentContext.Cfg.CommitVersion, nil, nil},
{"GIT_COMMIT_TIME", "", false, &agentContext.Cfg.CommitTime, nil, nil},
{"VERSION", "", false, &agentContext.Cfg.AppVersion, nil, nil},
{"GOLANG_ENV_MAXPROCS", "8", false, nil, nil, &agentContext.Cfg.GoMaxProcs},

{"SPIDERPOOL_LOG_LEVEL", logutils.LogInfoLevelStr, true, &agentContext.Cfg.LogLevel, nil, nil},
{"SPIDERPOOL_ENABLED_METRIC", "false", false, nil, &agentContext.Cfg.EnableMetric, nil},
Expand All @@ -74,8 +73,6 @@ type Config struct {
CommitVersion string
CommitTime string
AppVersion string
GoMaxProcs int

// flags
ConfigPath string

Expand Down
12 changes: 7 additions & 5 deletions cmd/spiderpool-agent/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/google/gops/agent"
"github.com/grafana/pyroscope-go"
"go.uber.org/automaxprocs/maxprocs"
"go.uber.org/zap"
apiruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -63,11 +64,12 @@ func DaemonMain() {
}

// Set golang max procs.
currentP := runtime.GOMAXPROCS(-1)
logger.Sugar().Infof("Default max golang procs: %d", currentP)
if currentP > int(agentContext.Cfg.GoMaxProcs) {
p := runtime.GOMAXPROCS(int(agentContext.Cfg.GoMaxProcs))
logger.Sugar().Infof("Change max golang procs to %d", p)
if _, err := maxprocs.Set(
maxprocs.Logger(func(s string, i ...interface{}) {
logger.Sugar().Infof(s, i...)
}),
); err != nil {
logger.Sugar().Warn("failed to set GOMAXPROCS")
}

// Load spiderpool's global Comfigmap.
Expand Down
2 changes: 0 additions & 2 deletions cmd/spiderpool-controller/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var envInfo = []envConf{
{"GIT_COMMIT_VERSION", "", false, &controllerContext.Cfg.CommitVersion, nil, nil},
{"GIT_COMMIT_TIME", "", false, &controllerContext.Cfg.CommitTime, nil, nil},
{"VERSION", "", false, &controllerContext.Cfg.AppVersion, nil, nil},
{"GOLANG_ENV_MAXPROCS", "8", false, nil, nil, &controllerContext.Cfg.GoMaxProcs},

{"SPIDERPOOL_LOG_LEVEL", logutils.LogInfoLevelStr, true, &controllerContext.Cfg.LogLevel, nil, nil},
{"SPIDERPOOL_ENABLED_METRIC", "false", false, nil, &controllerContext.Cfg.EnableMetric, nil},
Expand Down Expand Up @@ -111,7 +110,6 @@ type Config struct {
CommitVersion string
CommitTime string
AppVersion string
GoMaxProcs int

// flags
ConfigPath string
Expand Down
12 changes: 7 additions & 5 deletions cmd/spiderpool-controller/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/google/gops/agent"
"github.com/grafana/pyroscope-go"
"go.uber.org/automaxprocs/maxprocs"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -68,11 +69,12 @@ func DaemonMain() {
}

// Set golang max procs.
currentP := runtime.GOMAXPROCS(-1)
logger.Sugar().Infof("Default max golang procs: %d", currentP)
if currentP > int(controllerContext.Cfg.GoMaxProcs) {
p := runtime.GOMAXPROCS(int(controllerContext.Cfg.GoMaxProcs))
logger.Sugar().Infof("Change max golang procs to %d", p)
if _, err := maxprocs.Set(
maxprocs.Logger(func(s string, i ...interface{}) {
logger.Sugar().Infof(s, i...)
}),
); err != nil {
logger.Sugar().Warn("failed to set GOMAXPROCS")
}

// Load spiderpool's global Comfigmap.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ require k8s.io/component-base v0.29.4 // indirect

require (
github.com/hashicorp/go-multierror v1.1.1
go.uber.org/automaxprocs v1.5.3
k8s.io/kubectl v0.26.3
k8s.io/kubelet v0.29.2
tags.cncf.io/container-device-interface v0.6.2
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/projectcalico/api v0.0.0-20220722155641-439a754a988b h1:dW+UhJMzusDO6hqVGuCYeDxXWAzc7HnA9CsPN+uHPnA=
github.com/projectcalico/api v0.0.0-20220722155641-439a754a988b/go.mod h1:Avoy1rTN1GfeisnHGf3WhQNqR+BuGOcwfNFsdWX6OHE=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
Expand Down Expand Up @@ -606,6 +608,8 @@ go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1
go.opentelemetry.io/otel/trace v1.25.0/go.mod h1:hCCs70XM/ljO+BeQkyFnbK28SBIJ/Emuha+ccrCRT7I=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI=
go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
Expand Down
19 changes: 19 additions & 0 deletions vendor/go.uber.org/automaxprocs/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions vendor/go.uber.org/automaxprocs/internal/cgroups/cgroup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions vendor/go.uber.org/automaxprocs/internal/cgroups/cgroups.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading