diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c86827565e..72367a3fe2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -156,6 +156,13 @@ Improvements Contributed by @Kami. +* Speed up service start up time by speeding up runners registration on service start up by + re-using existing stevedore ``ExtensionManager`` instance instead of instantiating new + ``DriverManager`` instance per extension which is not necessary and it's slow since it requires + disk / pkg resources scan for each extension. (improvement) #5198 + + Contributed by @Kami. + Fixed ~~~~~ diff --git a/st2common/st2common/bootstrap/runnersregistrar.py b/st2common/st2common/bootstrap/runnersregistrar.py index bb99389433..3d30346b98 100644 --- a/st2common/st2common/bootstrap/runnersregistrar.py +++ b/st2common/st2common/bootstrap/runnersregistrar.py @@ -15,7 +15,6 @@ from __future__ import absolute_import -from stevedore.driver import DriverManager from stevedore.extension import ExtensionManager from st2common import log as logging @@ -41,15 +40,13 @@ def register_runners(experimental=False, fail_on_failure=True): runner_count = 0 manager = ExtensionManager(namespace=RUNNERS_NAMESPACE, invoke_on_load=False) - extension_names = manager.names() - for name in extension_names: + # NOTE: We use ExtensionManager directly instead of DriverManager per extension since that is + # much faster and allows us to reduce stevedore loading overhead for each runner + for extension in manager.extensions: + name = extension.name LOG.debug('Found runner "%s"' % (name)) - - manager = DriverManager( - namespace=RUNNERS_NAMESPACE, invoke_on_load=False, name=name - ) - runner_metadata = manager.driver.get_metadata() + runner_metadata = extension.plugin.get_metadata() runner_count += register_runner(runner_metadata, experimental) LOG.debug("End : register runners") @@ -99,7 +96,6 @@ def register_runner(runner_type, experimental): runner_type_model.id = runner_type_db.id try: - runner_type_db = RunnerType.add_or_update(runner_type_model) extra = {"runner_type_db": runner_type_db}