From a8e25b858dcd87e07a8aadaf08537c36a1aa7ab7 Mon Sep 17 00:00:00 2001 From: haixin Date: Sat, 2 Jan 2021 15:58:15 +0800 Subject: [PATCH] Put ensure_share into thread pool to speed up the startup of share service when we need to start or restart manila share service, will call init_host(). and call ensure_driver_resources() in init_host(), will call self.driver.ensure_shares or self.driver.ensure_share to update all share instances in that host. Currently, only NetApp and LVM implement self.driver.ensure_shares, Other manufacturers are using self.driver.ensure_share. in large-scale environment, there are lot of share instances in one host. this will lead to take much time to ensure_share. so we can put this operation into the thread pool to speed up the startup of the service. Closes-Bug: #1909847 Change-Id: I295d0de0958ebfedd89441f1a2c1b447b74693a0 --- manila/manager.py | 6 +++ manila/share/manager.py | 38 +++++++++++-------- ...are-into_thread-pool-e658f21c7caad668.yaml | 16 ++++++++ 3 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 releasenotes/notes/bug-1909847-put-ensure-share-into_thread-pool-e658f21c7caad668.yaml diff --git a/manila/manager.py b/manila/manager.py index d9cc5fef1c..3a5e86d475 100644 --- a/manila/manager.py +++ b/manila/manager.py @@ -51,6 +51,8 @@ This module provides Manager, a base class for managers. """ + +from eventlet import greenpool from oslo_config import cfg from oslo_log import log from oslo_service import periodic_task @@ -139,8 +141,12 @@ class SchedulerDependentManager(Manager): self.last_capabilities = None self.service_name = service_name self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI() + self._tp = greenpool.GreenPool() super(SchedulerDependentManager, self).__init__(host, db_driver) + def _add_to_threadpool(self, func, *args, **kwargs): + self._tp.spawn_n(func, *args, **kwargs) + def update_service_capabilities(self, capabilities): """Remember these capabilities to send on next periodic update.""" self.last_capabilities = capabilities diff --git a/manila/share/manager.py b/manila/share/manager.py index 299717ae2b..a5db38d7ab 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -131,6 +131,10 @@ share_manager_opts = [ 'configured, this option must be set to False. ' 'If set to False - gathering share usage size will be' ' disabled.'), + cfg.BoolOpt('share_service_inithost_offload', + default=False, + help='Offload pending share ensure during ' + 'share service startup'), ] CONF = cfg.CONF @@ -447,7 +451,12 @@ class ShareManager(manager.SchedulerDependentManager): LOG.exception("Caught exception trying ensure " "share instances.") else: - self._ensure_share(ctxt, update_share_instances) + for share_instance in update_share_instances: + if CONF.share_service_inithost_offload: + self._add_to_threadpool(self._ensure_share, + ctxt, share_instance) + else: + self._ensure_share(ctxt, share_instance) if new_backend_info: self.db.backend_info_update( @@ -517,20 +526,19 @@ class ShareManager(manager.SchedulerDependentManager): "access rules for snapshot instance %s.", snap_instance['id']) - def _ensure_share(self, ctxt, share_instances): - for share_instance in share_instances: - try: - export_locations = self.driver.ensure_share( - ctxt, share_instance, - share_server=share_instance['share_server']) - except Exception: - LOG.exception("Caught exception trying ensure " - "share '%(s_id)s'.", - {'s_id': share_instance['id']}) - continue - if export_locations: - self.db.share_export_locations_update( - ctxt, share_instance['id'], export_locations) + def _ensure_share(self, ctxt, share_instance): + export_locations = None + try: + export_locations = self.driver.ensure_share( + ctxt, share_instance, + share_server=share_instance['share_server']) + except Exception: + LOG.exception("Caught exception trying ensure " + "share '%(s_id)s'.", + {'s_id': share_instance['id']}) + if export_locations: + self.db.share_export_locations_update( + ctxt, share_instance['id'], export_locations) def _check_share_server_backend_limits( self, context, available_share_servers, share_instance=None): diff --git a/releasenotes/notes/bug-1909847-put-ensure-share-into_thread-pool-e658f21c7caad668.yaml b/releasenotes/notes/bug-1909847-put-ensure-share-into_thread-pool-e658f21c7caad668.yaml new file mode 100644 index 0000000000..2050a4326b --- /dev/null +++ b/releasenotes/notes/bug-1909847-put-ensure-share-into_thread-pool-e658f21c7caad668.yaml @@ -0,0 +1,16 @@ +--- +upgrade: + - | + This fix introduces a new configuration item, which named + "share_service_inithost_offload", default value is False, if set it True, + will put ensure_share operation into thread pool to speed up startup of + manila share service. +fixes: + - | + The manila share servie now can put ensure_share operation into thread + pool during service startup process. See `Launchpad bug#1890833 + `_ for more details. + - | + The manila share service now honors the configuration option + "share_service_inithost_offload", and it can be used to reduce the time + required for the manila share aervice to start up.