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')
pull/262/head
David Wilson 7 years ago
parent f7b368b1fb
commit 8d45e609ee

@ -227,6 +227,19 @@ class ContextService(mitogen.service.Service):
finally: finally:
self._lock.release() 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): def _connect(self, key, spec, via=None):
""" """
Actual connect implementation. Arranges for the Mitogen connection to Actual connect implementation. Arranges for the Mitogen connection to
@ -266,6 +279,7 @@ class ContextService(mitogen.service.Service):
mitogen.core.listen(stream, 'disconnect', mitogen.core.listen(stream, 'disconnect',
lambda: self._on_stream_disconnect(stream)) lambda: self._on_stream_disconnect(stream))
self._send_module_forwards(context)
home_dir = context.call(os.path.expanduser, '~') home_dir = context.call(os.path.expanduser, '~')
# We don't need to wait for the result of this. Ideally we'd check its # We don't need to wait for the result of this. Ideally we'd check its

Loading…
Cancel
Save