Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support spawn setting of 0 to mean number of cpus #2711

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 ath the same time")
dabarrell marked this conversation as resolved.
Show resolved Hide resolved
}
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