Skip to content

Commit

Permalink
Merge pull request #2711 from mmlb/spawn-0-workers
Browse files Browse the repository at this point in the history
Support spawn setting of 0 to mean number of cpus
  • Loading branch information
dabarrell committed Apr 17, 2024
2 parents e43e43e + 53675a3 commit ba14a12
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions clicommand/agent_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit ba14a12

Please sign in to comment.