Disallow excessive GOMAXPROCS (#368)

This commit is contained in:
petricadaipegsp 2024-11-20 23:59:09 +01:00 committed by GitHub
parent b94e123262
commit 8ce9aeee4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -34,4 +34,6 @@ type EngineConfig struct {
// Values used only for testing do not override these in production, your
// node will get kicked out
Difficulty uint32 `yaml:"difficulty"`
// Whether to allow GOMAXPROCS values above the number of physical cores.
AllowExcessiveGOMAXPROCS bool `yaml:"allowExcessiveGOMAXPROCS"`
}

View File

@ -394,6 +394,12 @@ func main() {
nodeConfig.Engine.DataWorkerMemoryLimit = 1792 * 1024 * 1024 // 1.75GiB
}
if len(nodeConfig.Engine.DataWorkerMultiaddrs) == 0 {
maxProcs, numCPU := runtime.GOMAXPROCS(0), runtime.NumCPU()
if maxProcs > numCPU && !nodeConfig.Engine.AllowExcessiveGOMAXPROCS {
fmt.Println("GOMAXPROCS is set higher than the number of available CPUs.")
os.Exit(1)
}
nodeConfig.Engine.DataWorkerCount = qruntime.WorkerCount(
nodeConfig.Engine.DataWorkerCount, true,
)