How do `serial`, `forks` and `throttle` interact?
AdvancedProductionPerformance and Scale
Answer
forksis the global upper limit on parallel workers on the controller.serialsplits the play's hosts into batches, and each batch runs the whole play before the next starts.throttlelimits concurrency of one task (or block), even if forks and the batch size are larger.
The effective parallelism for a task is min(forks, batch size, throttle). With serial: 50 and forks: 20, each batch of 50 runs 20 at a time. With serial: 1 and forks: 100, only one host is touched at a time.
- hosts: web
serial: [1, 5, "25%"]
tasks:
- ansible.builtin.command: /opt/app/bin/warm-cache
throttle: 2
More on Performance and Scale
Why can Ansible be slower than a shell script for 100 servers, and what dominates the time?BeginnerHow do you choose the `forks` value?BeginnerWhat is SSH pipelining and why does it help?BeginnerWhich SSH settings matter for performance and stability?IntermediateHow do you find out which tasks are slow?BeginnerHow do you reduce the cost of fact gathering?Intermediate