In August one of our larger tenants reported that scheduled patch runs were starting 10 to 15 minutes late. We looked at the execution nodes and found them at 40% CPU with plenty of free memory. Jobs were sitting in pending. Nothing was broken. The scheduler was doing exactly what we had told it to do.
How AWX decides a node is full
Each AWX instance has a capacity number, and each running job subtracts an impact from it. The impact of a job is roughly its forks value plus one. The task manager will not start a job on an instance unless the instance has that much capacity left.
Capacity itself is derived from two numbers:
- CPU capacity: cores multiplied by
SYSTEM_TASK_FORKS_CPU, which defaults to 4 forks per core. - Memory capacity: (RAM minus a 2 GB reserve) divided by
SYSTEM_TASK_FORKS_MEM, which defaults to 100 MB per fork.
The instance's capacity_adjustment slider, from 0.0 to 1.0, picks a point between the smaller and the larger of those two numbers. At 0.0 you get the minimum. At 1.0 you get the maximum.
For one of our 8 vCPU, 16 GB execution nodes:
| Forks | |
|---|---|
| CPU capacity (8 x 4) | 32 |
| Memory capacity ((16384 - 2048) / 100) | 143 |
| Capacity at adjustment 0.0 | 32 |
| Capacity at adjustment 0.5 | 87 |
| Capacity at adjustment 1.0 | 143 |
What we had done
A year ago, after an overcommit incident on a different tenant, we set capacity_adjustment to 0.0 across the fleet. That made capacity equal to the CPU number, 32 forks per node. It is a safe setting if your jobs are CPU-bound. Ours are not. A patch run is mostly waiting: waiting for SSH to connect, waiting for a package mirror, waiting for apt to take a lock. The ansible-playbook processes sit at a few percent CPU each.
This tenant's main template ran with forks: 50 against 300 hosts. Its impact was 51. Two nodes with a capacity of 32 each could never run it at all, so the job was placed only when the third node, with a larger instance type, was free. Everything else queued behind it.
The fix
We did three things, in order of how much they mattered.
1. Set the slider per node type. For general execution nodes we now use 0.5, which gives 87 forks on the box above. You can read and change it through the API:
$ curl -s -H "Authorization: Bearer $TOKEN" \
https://tenant.runbooks.ansiblecloud.io/api/v2/instances/ | \
jq '.results[] | {hostname, capacity, consumed_capacity, capacity_adjustment}'
$ curl -s -X PATCH -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"capacity_adjustment": "0.5"}' \
https://tenant.runbooks.ansiblecloud.io/api/v2/instances/4/
2. Make forks honest. A template with 300 hosts does not need 50 forks if each host takes ten seconds. We measured wall-clock per host and picked the smallest value that kept the run under the window. Most templates ended up between 15 and 25. This is the single biggest lever, because it shrinks the impact of every job.
3. Fix the slow part of the job. We turned on SSH pipelining and ControlPersist in the project's ansible.cfg, and pointed apt at the site-local mirror instead of the default. Per-host time dropped from about 70 seconds to about 25, which meant fewer forks for the same window.
[defaults]
forks = 20
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/facts
fact_caching_timeout = 3600
[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=120s
Other things that were not the problem
We checked Redis, which AWX uses for the dispatcher and for websocket fan-out, and it was fine at 90 MB resident. We checked Postgres write latency from the callback receiver, which looked normal. If your queue is slow and your nodes are busy, those are the next places to look, along with JOB_EVENT_WORKERS. Ours were not the limit.
Result
| Before | After | |
|---|---|---|
p95 time in pending | 9 min 40 s | 48 s |
| Peak node CPU | 41% | 63% |
| Patch window used | 71 min | 34 min |
We now alert when consumed_capacity is under 50% of capacity while more than three jobs are pending. That combination is the signature of this exact mistake, and it is cheap to detect.
Written by Priya Nair. Comments, corrections and arguments to priya.nair@ansiblecloud.io.