Overview

Date: 2026-05-11

Time: 15:42

Overview

This is a benchmark and demonstration script that compares FTL2's in-process Python module system against traditional subprocess-based execution (as used by Ansible). It measures timing for file operations, command execution, the async executor API, and batch vs sequential execution, showing that FTL modules achieve ~250x+ speedup by eliminating subprocess overhead. It also serves as a usage-pattern reference for the four main ways to invoke FTL modules.

Usage Patterns

The script demonstrates four invocation styles, from lowest-level to highest:

1. Direct synchronous call:


from ftl2.ftl_modules import ftl_file, ftl_command
result = ftl_file(path='/tmp/test', state='touch')  # returns dict with 'changed' key
result = ftl_command(cmd='echo hello')

2. Async execute() with auto module selection:


from ftl2.ftl_modules import execute
result = await execute('file', {'path': '/tmp/test', 'state': 'touch'})
# result.success, result.used_ftl

3. Convenience run() function (kwargs instead of dict):


from ftl2.ftl_modules import run
result = await run('command', cmd='echo hello')
# result.output['stdout']

4. Concurrent multi-host execution:


from ftl2.ftl_modules import execute_on_hosts, LocalHost
hosts = [LocalHost(name=f'host{i}') for i in range(3)]
results = await execute_on_hosts(hosts, 'command', {'cmd': 'echo ok'})

5. Batch execution (concurrent tasks):


from ftl2.ftl_modules import execute_batch
tasks = [('command', {'cmd': 'true'}, None) for _ in range(10)]
await execute_batch(tasks)

API and Configuration

No config files or environment variables. The script adds src/ to sys.path for development imports.

Key Behaviors

Relationships