Skip to content

Commit e4b651a

Browse files
ldezpull[bot]
authored andcommitted
feat: automatically adjust the maximum concurrency to the container CPU quota (#4441)
1 parent 29d1456 commit e4b651a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ require (
124124
gitlab.com/bosi/decorder v0.4.1
125125
go-simpler.org/musttag v0.9.0
126126
go-simpler.org/sloglint v0.4.0
127+
go.uber.org/automaxprocs v1.5.3
127128
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
128129
golang.org/x/tools v0.18.0
129130
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/commands/run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/spf13/cobra"
2424
"github.com/spf13/pflag"
2525
"github.com/spf13/viper"
26+
"go.uber.org/automaxprocs/maxprocs"
2627
"golang.org/x/exp/maps"
2728
"gopkg.in/yaml.v3"
2829

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

157-
runtime.GOMAXPROCS(c.cfg.Run.Concurrency)
158+
if c.cfg.Run.Concurrency == 0 {
159+
// Automatically set GOMAXPROCS to match Linux container CPU quota.
160+
_, _ = maxprocs.Set(nil)
161+
} else {
162+
runtime.GOMAXPROCS(c.cfg.Run.Concurrency)
163+
}
158164

159165
return c.startTracing()
160166
}

0 commit comments

Comments
 (0)