Files
mesh-sdk/go/buildstep/cpu.go
T
jschoubben 04902ff24a Build seats yield: idle priority and a per-node processor cap on their runtimes, threads per step within it (issue 1806)
The operator's desktop slows while it builds: the Go build runtime took 1650% of
shanks' 24 processors with nothing holding it back. A build seat's holder now
runs its runtime at idle priority under its node's cpu-cap share (declaration
Yields, composed from Seat.Yields and the module's cpu-cap setting), and
buildcpu/buildstep give each step its part of that cap in threads.
2026-10-26 13:37:00 +01:00

41 lines
1.5 KiB
Go

package buildstep
import (
"encoding/json"
"os"
"git.novox.be/novox/mesh-sdk/go/buildcpu"
)
// NodeLimits is what one step on node is held to (novox/hq issue 1806): the node's processor cap from the module's
// settings file at path (buildcpu.Setting, its default when the file does not set it), the machine's processors, and
// the node's capacity, so the steps that run at once start no more threads together than the cap gives. Read at every
// call, like the capacity, so a change takes effect at the next step. A file or a setting that cannot be read gives the
// default cap and says why: a step still runs with a bound, never without one.
func NodeLimits(path, node string, slots int, logf func(string, ...any)) buildcpu.Limits {
setting := buildcpu.Defaults
if path != "" {
if raw, err := os.ReadFile(path); err != nil {
sayTo(logf, "the processor cap cannot be read, so %s builds under the default cap: %v", node, err)
} else {
var s map[string]any
if err := json.Unmarshal(raw, &s); err != nil {
sayTo(logf, "the settings file %s is not JSON, so %s builds under the default cap: %v", path, node, err)
} else if v, ok := s[buildcpu.Setting].(string); ok {
setting = v
}
}
}
l, err := buildcpu.LimitsFor(setting, node, slots)
if err != nil {
sayTo(logf, "%v, so %s builds under the default cap of %d%%", err, node, buildcpu.DefaultPercent)
}
return l
}
func sayTo(logf func(string, ...any), format string, args ...any) {
if logf != nil {
logf(format, args...)
}
}