Skip to content

Commit

Permalink
lintcmd/runner: use GOMAXPROCS instead of NumCPU
Browse files Browse the repository at this point in the history
GOMAXPROCS subsumes NumCPU for the purpose of sizing semaphores. If
users set CPU affinity, then GOMAXPROCS will reflect that. If users
only set GOMAXPROCS, then NumCPU would be inaccurate. Additionally,
there are plans to make GOMAXPROCS aware of CPU quotas
(golang/go#33803).

Users are still advised to set CPU affinity instead of relying on
GOMAXPROCS to limit CPU usage, because Staticcheck shells out to the
underlying build system, which together with Staticcheck would be able
to use more CPU than intended if limited by just GOMAXPROCS.
  • Loading branch information
dominikh committed Jun 14, 2020
1 parent 9cc924a commit d49b8de
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lintcmd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
//
// Actions are executed in parallel where the dependency graph allows.
// Overall parallelism is bounded by a semaphore, sized according to
// runtime.NumCPU(). Each concurrently processed package takes up a
// GOMAXPROCS. Each concurrently processed package takes up a
// token, as does each analyzer – but a package can always execute at
// least one analyzer, using the package's token.
//
// Depending on the overall shape of the graph, there may be NumCPU
// Depending on the overall shape of the graph, there may be GOMAXPROCS
// packages running a single analyzer each, a single package running
// NumCPU analyzers, or anything in between.
// GOMAXPROCS analyzers, or anything in between.
//
// Total memory consumption grows roughly linearly with the number of
// CPUs, while total execution time is inversely proportional to the
Expand Down Expand Up @@ -353,7 +353,7 @@ func New(cfg config.Config) (*Runner, error) {
return &Runner{
cfg: cfg,
cache: cache,
semaphore: tsync.NewSemaphore(runtime.NumCPU()),
semaphore: tsync.NewSemaphore(runtime.GOMAXPROCS(0)),
}, nil
}

Expand Down

0 comments on commit d49b8de

Please sign in to comment.