Skip to content

Commit

Permalink
Merge pull request #5198 from StackStorm/speed_up_runner_registration
Browse files Browse the repository at this point in the history
Speed up service start up time by reducing runner registration / extension loading time
  • Loading branch information
Kami authored Mar 21, 2021
2 parents da76504 + 6698226 commit b05e1ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~

Expand Down
14 changes: 5 additions & 9 deletions st2common/st2common/bootstrap/runnersregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit b05e1ae

Please sign in to comment.