diff --git a/clicommand/agent_start.go b/clicommand/agent_start.go index a0eb564940..b8468bd22e 100644 --- a/clicommand/agent_start.go +++ b/clicommand/agent_start.go @@ -78,6 +78,7 @@ type AgentStartConfig struct { Name string `cli:"name"` Priority string `cli:"priority"` Spawn int `cli:"spawn"` + SpawnPerCPU int `cli:"spawn-per-cpu"` SpawnWithPriority bool `cli:"spawn-with-priority"` RedactedVars []string `cli:"redacted-vars" normalize:"list"` CancelSignal string `cli:"cancel-signal"` @@ -610,13 +611,19 @@ var AgentStartCommand = cli.Command{ }, cli.IntFlag{ Name: "spawn", - Usage: "The number of agents to spawn in parallel", + Usage: "The number of agents to spawn in parallel (mutually exclusive with --spawn-per-cpu)", Value: 1, EnvVar: "BUILDKITE_AGENT_SPAWN", }, + cli.IntFlag{ + Name: "spawn-per-cpu", + Usage: "The number of agents to spawn per cpu in parallel (mutually exclusive with --spawn)", + Value: 0, + EnvVar: "BUILDKITE_AGENT_SPAWN_PER_CPU", + }, cli.BoolFlag{ Name: "spawn-with-priority", - Usage: "Assign priorities to every spawned agent (when using --spawn) equal to the agent's index", + Usage: "Assign priorities to every spawned agent (when using --spawn or --spawn-per-cpu) equal to the agent's index", EnvVar: "BUILDKITE_AGENT_SPAWN_WITH_PRIORITY", }, cancelSignalFlag, @@ -1093,6 +1100,13 @@ var AgentStartCommand = cli.Command{ Features: cfg.Features(ctx), } + if cfg.SpawnPerCPU > 0 { + if cfg.Spawn > 1 { + return errors.New("You can't specify spawn and spawn-per-cpu at the same time") + } + cfg.Spawn = runtime.NumCPU() * cfg.SpawnPerCPU + } + // Spawning multiple agents doesn't work if the agent is being // booted in acquisition mode if cfg.Spawn > 1 && cfg.AcquireJob != "" {