From 7eae65e13f83bbdd08710b4cb551f98855df5c2e Mon Sep 17 00:00:00 2001 From: Carter Dodd Date: Mon, 6 Jun 2022 17:43:33 -0500 Subject: [PATCH] Add process max reserve --- internal/pkg/util/util.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index 811e39ed..05ebfe0d 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -22,8 +22,10 @@ import ( "github.com/pkg/errors" ) +// reserve some number of cpus for system/warwulfd usage +var processLimitedReserve int = 4 // maximum number of concurrent spawned processes -var processLimitedMax = runtime.NumCPU() +var processLimitedMax = MaxInt(1, runtime.NumCPU() - processLimitedReserve) // Channel used as semaphore to specififed processLimitedMax var processLimitedChan = make(chan int, processLimitedMax) // Current number of processes started + queued @@ -51,6 +53,14 @@ func ProcessLimitedStatus() (running int32, queued int32) { return } +func MaxInt( a int, b int ) int { + if a > b { + return a + } + + return b +} + func FirstError(errs ...error) (err error) { for _, e := range errs { if err == nil { @@ -694,14 +704,14 @@ func RunWWCTL(args ...string) (out []byte, err error) { defer ProcessLimitedExit() running, queued := ProcessLimitedStatus() - wwlog.Debug("Starting wwctl process %d (%d running, %d queued): %v", + wwlog.Verbose("Starting wwctl process %d (%d running, %d queued): %v", index, running, queued, args ) proc := exec.Command("wwctl", args...) out, err = proc.CombinedOutput() - wwlog.Debug("Finished wwctl process %d", index) + wwlog.Verbose("Finished wwctl process %d", index) return out, err }