From 8d45e609ee35d22fd1940eb082b6620f00cfea3d Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 29 May 2018 13:34:20 +0100 Subject: [PATCH] ansible: preload always-requested modules. Avoid 9 roundtrips during setup. In combination with previous change, reduces 'ansible -m stat' execution over 25ms link from 3.7s to 3.07s. 1,3d0 < _on_get_module('ansible') < _on_get_module('ansible.module_utils') < _on_get_module('ansible.module_utils.basic') 69,74d65 < _on_get_module('ansible.module_utils.json_utils') < _on_get_module('ansible.release') < _on_get_module('ansible_mitogen') < _on_get_module('ansible_mitogen.runner') < _on_get_module('ansible_mitogen.target') < _on_get_module('mitogen.fork') --- ansible_mitogen/services.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ansible_mitogen/services.py b/ansible_mitogen/services.py index 24e1f5b1..ee4ca010 100644 --- a/ansible_mitogen/services.py +++ b/ansible_mitogen/services.py @@ -227,6 +227,19 @@ class ContextService(mitogen.service.Service): finally: self._lock.release() + ALWAYS_PRELOAD = ( + 'ansible_mitogen.target', + 'ansible.release', + 'ansible.module_utils.json_utils', + 'ansible_mitogen.runner', + 'mitogen.fork', + 'ansible.module_utils.basic', + ) + + def _send_module_forwards(self, context): + for fullname in self.ALWAYS_PRELOAD: + self.router.responder.forward_module(context, fullname) + def _connect(self, key, spec, via=None): """ Actual connect implementation. Arranges for the Mitogen connection to @@ -266,6 +279,7 @@ class ContextService(mitogen.service.Service): mitogen.core.listen(stream, 'disconnect', lambda: self._on_stream_disconnect(stream)) + self._send_module_forwards(context) home_dir = context.call(os.path.expanduser, '~') # We don't need to wait for the result of this. Ideally we'd check its