Slow Servers' Gemlog: Ansible vs Rex Bandwidth Usage
Posted: 2026-02-03
Back in January I made some comparisons between Ansible and Rex. Since then, I noticed that Ansible has a rather impressively high amount of bandwidth usage, leading to more testing.
Ansible vs Rex (previous post)
The Test
I wanted a minimal test case to see if my suspicions about bandwidth usage were correct.
Ansible
Version: 12.0.0
---
- name: bwtest
hosts: slowservers.net
gather_facts: False
tasks:
- name: Add /ihavecontent
ansible.builtin.copy:
dest: /ihavecontent
content: "Content.\n"
Rex
Version: 1.16.1
group bwtest => 'slowservers.net',
task 'bwtest',
group => 'bwtest',
sub {
file "/ihavecontent",
content => "Content.";
};
Execution
I had nothing else running and used bwm-ng to show the sum of traffic from running the scripts. A small amount of bandwidth was consumed over local ICMP/ICMPv6 traffic, but not enough to matter much. bwm-ng was ran only for the duration of each test to try and make it as accurate as possible.
Ansible
Duration: 11 seconds.
Bandwidth:
- RX: 36.63 KB
- TX: 286.70 KB
- RX+TX: 323.33 KB
Rex
Duration: 5 seconds
- RX: 23.32 KB
- TX: 19.32 KB
- RX+TX: 42.74KB
Thoughts so far
Here, Rex is twice as fast and uses less than 1/7th of the bandwidth. Ansible is looking like quite the hog here.
Let's add an extra statement to each test.
Ansible
---
- name: bwtest
hosts: slowservers.net
gather_facts: False
tasks:
- name: Add /ihavecontent
ansible.builtin.copy:
dest: /ihavecontent
content: "Content.\n"
- name: Add /ihavecontent2
ansible.builtin.copy:
dest: /ihavecontent2
content: "Content.\n"
- Duration: 17.8 seconds
- RX: 53.9 3KB
- TX: 554.6 KB
- RX+TX: 608.54 KB
It looks like we added 6.8 seconds for one additional statement that is about as small as it could possibly get.
Now we've almost doubled the bandwidth usage going from one statement to two. It looks like it's roughly 300 KB per statement.
Rex
The astute may have observed that Rex adds a newline with content automatically and Ansible does not. I don't think this is necessarily a pro or a con, just a difference to keep in mind when writing either.
group bwtest => 'slowservers.net',
task 'bwtest',
group => 'bwtest',
sub {
file "/ihavecontent",
content => "Content.";
file "/ihavecontent2",
content => "Content.";
};
- Duration: 5.6 seconds
- RX: 27.47 KB
- TX: 24.50 KB
- RX+TX: 51.97 KB
About 8 KB and 600 miliseconds for an extra statement. Now Rex is using less than 10% of the bandwidth that Ansible is, and it runs 3x faster.
Conclusion
I didn't make this a perfect test with precise timings, 3 runs, etc, but this gives a good and general idea.
Ansible bandwidth may not sound like much of an issue, but keep in mind that this is an absolutely minimal example. We're not even gathering facts, which Ansible does by default, and many playbooks need. Gathering facts takes more time and seems to use about 300KB more bandwidth.
Many playbooks have tens or hundreds of statements.. And maybe you're running these from a DSL connection, Starlink, coffee shop wifi, etc, and you have about 10Mbit/sec upload to work with. And lets say that you want to manage 3 servers at once. Maybe 10 at once? What about 100? The bandwidth usage alone can be prohibitive.
I like writing Ansible, but this aspect is very disappointing.
Some may be aware that there's a plugin for Ansible called 'Mitogen for Ansible' that is supposed to speed up Ansible considerably. If you're already using Ansible, or you have want to write anything more than a hello world playbook, it's probably worth checking out. I am not sure how it works in practice. I may have used it before, but I can't remember.
Mitogen for Ansible
One more bit about Rex
I mentioned in the last post that I hoped for a way for Rex to work in parallel. I played with the batch setting and didn't have any luck with it. I finally noticed that there is a parallelism configuration, both on the CLI and in the Rexfiles. It appears to work exactly as I hoped.
Return to the gemlog
Return to the index