From d49b8deb7c27ceff53894fbbbb0f604587efb075 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sun, 14 Jun 2020 18:52:52 +0200 Subject: [PATCH] lintcmd/runner: use GOMAXPROCS instead of NumCPU 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 (https://github.com/golang/go/issues/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. --- lintcmd/runner/runner.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lintcmd/runner/runner.go b/lintcmd/runner/runner.go index b3c245a43..867d192f0 100644 --- a/lintcmd/runner/runner.go +++ b/lintcmd/runner/runner.go @@ -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 @@ -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 }