Skip to content

Commit fcad351

Browse files
committed
Default GOMAXPROCS to 1
Avoid running on all CPUs by limiting the Go runtime to one CPU by default. Avoids having Go routines schedule on every CPU, driving up the visible run queue length on high CPU count systems. This also helps workaround a kernel deadlock issue with reading from sysfs concurrently. See: * #1880 * #2500 Signed-off-by: Ben Kochie <[email protected]>
1 parent 956a3f8 commit fcad351

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* [ENHANCEMENT]
66
* [BUGFIX]
77

8+
* [CHANGE] Default GOMAXPROCS to 1
9+
810
## 1.4.0 / 2022-09-24
911

1012
* [CHANGE] Merge metrics descriptions in textfile collector #2475

node_exporter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
_ "net/http/pprof"
2121
"os"
2222
"os/user"
23+
"runtime"
2324
"sort"
2425

2526
"github.com/prometheus/common/promlog"
@@ -159,6 +160,9 @@ func main() {
159160
"collector.disable-defaults",
160161
"Set all collectors to disabled by default.",
161162
).Default("false").Bool()
163+
maxProcs = kingpin.Flag(
164+
"runtime.gomaxprocs", "The target number of CPUs Go will run on (GOMAXPROCS)",
165+
).Envar("GOMAXPROCS").Default("1").Int()
162166
toolkitFlags = kingpinflag.AddFlags(kingpin.CommandLine, ":9100")
163167
)
164168

@@ -178,6 +182,8 @@ func main() {
178182
if user, err := user.Current(); err == nil && user.Uid == "0" {
179183
level.Warn(logger).Log("msg", "Node Exporter is running as root user. This exporter is designed to run as unprivileged user, root is not required.")
180184
}
185+
runtime.GOMAXPROCS(*maxProcs)
186+
level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", *maxProcs)
181187

182188
http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, logger))
183189
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)