# Priorities with spawn config

**URL:** <https://forum.buildkite.community/t/priorities-with-spawn-config/4400>\
**Category:** General\
**Created:** [June 3, 2025, 11:48am UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400 "2025-06-03T11:48:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valkum](https://avatars.discourse-cdn.com/v4/letter/v/96bed5/32.png) [@Valkum](https://forum.buildkite.community/u/Valkum)\
**Post date:** [June 3, 2025, 11:48am UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/1 "2025-06-03T11:48:51Z")

</div>

We have two bare-metal machines running 10 instances each to get good pipeline speeds.  
We utilize the spawn config to spawn 10 instances on each host ([Buildkite Agent configuration v3 | Buildkite Documentation](https://buildkite.com/docs/agent/v3/configuration#spawn)). We would like to apply priorities to schedule jobs equally on both machines.

Are there ways to let the spawn implementation assign increasing priorities to each spawned instance?

We had an issue in the past where one host wasn’t able to spawn new os threads/processes due to disk space issues. The agents weren’t timing out, as they were already running and were able to reach the buildkite backend. But they weren’t able to spawn new tasks, though they were still picking up jobs. No jobs got scheduled on the second working host for some reason.  
We hope we can prevent such issues by assigning priorities to our agent instances.

---

<div class="post-metadata">

**Author:** ![Micheal](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/micheal/32/1588_2.png) [@Micheal](https://forum.buildkite.community/u/Micheal)\
**Post date:** [June 3, 2025, 2:31pm UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/2 "2025-06-03T14:31:57Z")

</div>

Hi @Valkum You can use agent priority value to distribute the job processes across both machines that would be running the agents. Please can you let me know if you already reviewed this [article](https://buildkite.com/docs/agent/v3/prioritization) on agent prioritization and [this](https://buildkite.com/docs/pipelines/configure/workflows/managing-priorities) on job prioritization and let me know if this helps your use case as it provides more details on the configuration. Thanks

---

<div class="post-metadata">

**Author:** ![Micheal](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/micheal/32/1588_2.png) [@Micheal](https://forum.buildkite.community/u/Micheal)\
**Post date:** [June 3, 2025, 4:31pm UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/3 "2025-06-03T16:31:04Z")

</div>

Hi @Valkum also wanted to add that my last comment means you would no longer use `spawn` for this use case because using both `spawn` and `priority` with an Agent will mean all the Agents spawned will have the same priority. If that was used in this case, it would either mean one or both of your Instances would have Agents with matching Priority which puts them in the same position as they are now. Given your use case, you can use multiple `buildkite-agent start --priority X` instead. This can be implemented in multiple ways e.g a a one line command loop or via the buidlkite configuration file. More details on how this can be implemented can also be found in this [document](https://buildkite.com/docs/agent/v3/prioritization#load-balancing) shared earlier

---

<div class="post-metadata">

**Author:** ![Valkum](https://avatars.discourse-cdn.com/v4/letter/v/96bed5/32.png) [@Valkum](https://forum.buildkite.community/u/Valkum)\
**Post date:** [June 3, 2025, 5:09pm UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/4 "2025-06-03T17:09:26Z")

</div>

What solution do you have in mind using the buildkite configuration file? We currently utilize systemd to start the agent (which then spawns N instances). We can clearly work something out using systemd (see below) but we would like to keep using spawn.

```auto
[Unit]
Description="Agent instance #%i"

[Service]
Type=simple
ExecStart=..... %i

```

```auto
[Unit]
Description=buildkite-agents
Requires=buildkite-agent@1.service buildkite-agent@2.service buildkite-agent@3.service

[Install]
WantedBy=multi-user.target

```

---

<div class="post-metadata">

**Author:** ![Micheal](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/micheal/32/1588_2.png) [@Micheal](https://forum.buildkite.community/u/Micheal)\
**Post date:** [June 3, 2025, 9:17pm UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/5 "2025-06-03T21:17:35Z")

</div>

Hi @Valkum Please can you let me know how you spin up the agents with `spawn` so we can get a better understanding of your use case. I believe as mentioned earlier you could also use the command line and run `buildkite-agent start --priority X` when starting up the agent but will hope to get a better understanding when we see your process of spinning up the agents with `spawn`.

---

<div class="post-metadata">

**Author:** ![Valkum](https://avatars.discourse-cdn.com/v4/letter/v/96bed5/32.png) [@Valkum](https://forum.buildkite.community/u/Valkum)\
**Post date:** [June 4, 2025, 11:40am UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/6 "2025-06-04T11:40:18Z")

</div>

We have a systemd unit:

```auto
[Unit]
Description=Buildkite Agent
Documentation=https://buildkite.com/agent
After=syslog.target
After=network.target

[Service]
Type=simple
User=buildkite-agent
Environment=HOME=/var/lib/buildkite-agent
ExecStart=/usr/bin/buildkite-agent start
RestartSec=5
Restart=on-failure
RestartForceExitStatus=SIGPIPE
TimeoutStartSec=10
TimeoutStopSec=0
KillMode=process

[Install]
WantedBy=multi-user.target

```

and the following content in our buildkite-agent.cfg

```auto
name="%hostname-%spawn"
spawn=10
...

```

---

<div class="post-metadata">

**Author:** ![Micheal](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/micheal/32/1588_2.png) [@Micheal](https://forum.buildkite.community/u/Micheal)\
**Post date:** [June 4, 2025, 3:07pm UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/7 "2025-06-04T15:07:14Z")

</div>

Hi @Valkum thanks for sharing this. I believe you can start the agent with this [configuration](https://buildkite.com/docs/agent/v3/cli-start#spawn-with-priority) `buildkite-agent start --spawn 10 --spawn-with-priority` as an example. This will result in 10 agent processes spawning and will assign a priority to each agent matching its spawn number. So with 2 different machines running your 10 agents via this start command, work will be dispatched to the agents with priority 10, then priority 9, etc. This will load balance the scheduled jobs across the machine equally

---

<div class="post-metadata">

**Author:** ![Valkum](https://avatars.discourse-cdn.com/v4/letter/v/96bed5/32.png) [@Valkum](https://forum.buildkite.community/u/Valkum)\
**Post date:** [June 6, 2025, 10:12am UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/8 "2025-06-06T10:12:16Z")

</div>

> [@Micheal](#):
>
> spawn-with-priority

Thanks! Works perfectly.  
Just for future readers: This also works in the config file with `spawn-with-priority=true`  
Might be worth adding this to [Buildkite Agent configuration v3 | Buildkite Documentation](https://buildkite.com/docs/agent/v3/configuration)

---

<div class="post-metadata">

**Author:** ![tomwatt](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tomwatt](https://forum.buildkite.community/u/tomwatt)\
**Post date:** [June 6, 2025, 10:29am UTC](https://forum.buildkite.community/t/priorities-with-spawn-config/4400/9 "2025-06-06T10:29:34Z")

</div>

Hey @Valkum

Thanks for pointing it is missing from our docs page on the Agent configuration, we will get that fixed!

Cheers,  
Tom
