Skip to content

Commit 2b44d59

Browse files
committed
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
1 parent 2b3b57e commit 2b44d59

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

ansible_mitogen/strategy.py

+26
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ def _add_plugin_paths(self):
211211
os.path.join(base_dir, 'action')
212212
)
213213

214+
def _queue_task(self, host, task, task_vars, play_context):
215+
"""
216+
Many PluginLoader caches are defective as they are only populated in
217+
the ephemeral WorkerProcess. Touch each plug-in path before forking to
218+
ensure all workers receive a hot cache.
219+
"""
220+
ansible_mitogen.loaders.module_loader.find_plugin(
221+
name=task.action,
222+
mod_type='',
223+
)
224+
ansible_mitogen.loaders.connection_loader.get(
225+
name=play_context.connection,
226+
class_only=True,
227+
)
228+
ansible_mitogen.loaders.action_loader.get(
229+
name=task.action,
230+
class_only=True,
231+
)
232+
233+
return super(StrategyMixin, self)._queue_task(
234+
host=host,
235+
task=task,
236+
task_vars=task_vars,
237+
play_context=play_context,
238+
)
239+
214240
def run(self, iterator, play_context, result=0):
215241
"""
216242
Arrange for a mitogen.master.Router to be available for the duration of

0 commit comments

Comments
 (0)