From 00ae90b2b232f2f544667eb98ca74bad3844f3c2 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 30 Jan 2019 19:40:23 +0000 Subject: [PATCH] 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 --- ansible_mitogen/strategy.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ansible_mitogen/strategy.py b/ansible_mitogen/strategy.py index 9cdb6a94..821d63d2 100644 --- a/ansible_mitogen/strategy.py +++ b/ansible_mitogen/strategy.py @@ -211,6 +211,32 @@ class StrategyMixin(object): 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