Skip to content
Permalink
Browse files
ansible: preheat PluginLoader caches before fork.
This has been broken for some time, but somehow it has become noticeable
on recent Ansible.

loop-100-tasks.yml before:
      15.532724001 seconds time elapsed
       8.453850000 seconds user
       5.808627000 seconds sys

loop-100-tasks.yml after:
       8.991635735 seconds time elapsed
       5.059232000 seconds user
       2.578842000 seconds sys
  • Loading branch information
dw committed Jan 30, 2019
1 parent 2b3b57e commit 2b44d598b7a2d65ad2db20b798ec664464a0a7c5
Showing with 26 additions and 0 deletions.
  1. +26 −0 ansible_mitogen/strategy.py
@@ -211,6 +211,32 @@ def _add_plugin_paths(self):
os.path.join(base_dir, 'action')
)

def _queue_task(self, host, task, task_vars, play_context):
"""
Many PluginLoader caches are defective as they are only populated in
the ephemeral WorkerProcess. Touch each plug-in path before forking to
ensure all workers receive a hot cache.
"""
ansible_mitogen.loaders.module_loader.find_plugin(
name=task.action,
mod_type='',
)
ansible_mitogen.loaders.connection_loader.get(
name=play_context.connection,
class_only=True,
)
ansible_mitogen.loaders.action_loader.get(
name=task.action,
class_only=True,
)

return super(StrategyMixin, self)._queue_task(
host=host,
task=task,
task_vars=task_vars,
play_context=play_context,
)

def run(self, iterator, play_context, result=0):
"""
Arrange for a mitogen.master.Router to be available for the duration of

0 comments on commit 2b44d59

Please sign in to comment.