Skip to content

Commit

Permalink
Merge pull request spidernet-io#4014 from spidernet-io/update-v09/GOM…
Browse files Browse the repository at this point in the history
…AXPROCS

Update GOMAXPROCS configuration
  • Loading branch information
weizhoublue committed Sep 4, 2024
2 parents 827b334 + 2ba257c commit a0a9f87
Show file tree
Hide file tree
Showing 20 changed files with 1,057 additions and 16 deletions.
3 changes: 0 additions & 3 deletions cmd/spiderpool-agent/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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 @@ -72,8 +71,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 @@ -62,11 +63,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 @@ -51,7 +51,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 @@ -109,7 +108,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/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -65,11 +66,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
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ require github.com/google/go-cmp v0.6.0 // indirect

require k8s.io/component-base v0.29.4 // indirect

require k8s.io/kubectl v0.26.3
require (
go.uber.org/automaxprocs v1.5.3
k8s.io/kubectl v0.26.3
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,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 @@ -581,6 +583,8 @@ go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
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

0 comments on commit a0a9f87

Please sign in to comment.