Skip to content

Commit

Permalink
feat: automatically adjust the maximum concurrency to the container C…
Browse files Browse the repository at this point in the history
…PU quota (#4441)
  • Loading branch information
ldez committed Mar 3, 2024
1 parent 61f2f70 commit b1eed50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ require (
gitlab.com/bosi/decorder v0.4.1
go-simpler.org/musttag v0.9.0
go-simpler.org/sloglint v0.4.0
go.uber.org/automaxprocs v1.5.3
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/tools v0.18.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum

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

8 changes: 7 additions & 1 deletion pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/automaxprocs/maxprocs"
"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -154,7 +155,12 @@ func (c *runCommand) persistentPreRunE(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't load config: %w", err)
}

runtime.GOMAXPROCS(c.cfg.Run.Concurrency)
if c.cfg.Run.Concurrency == 0 {
// Automatically set GOMAXPROCS to match Linux container CPU quota.
_, _ = maxprocs.Set(nil)
} else {
runtime.GOMAXPROCS(c.cfg.Run.Concurrency)
}

return c.startTracing()
}
Expand Down

0 comments on commit b1eed50

Please sign in to comment.