From c1f0ac1302a064bc5d2cbeceb7cf8a17d531956d Mon Sep 17 00:00:00 2001 From: Junyuan Leng Date: Thu, 14 Apr 2016 15:46:59 +0800 Subject: [PATCH] Make the notifier max_workers configurable Make the max_workers attribute of NotifierDriver configurable. Now it can be configured using 'max_workers' parameter. Default value of max_workers is 10. Co-Authored-By: wangxiyuan Change-Id: Ice7d12199f8463793951932b48408e7df81440f2 --- zaqar/common/configs.py | 2 ++ zaqar/notification/notifier.py | 4 ++-- zaqar/storage/pipeline.py | 4 +++- zaqar/tests/base.py | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/zaqar/common/configs.py b/zaqar/common/configs.py index af49b0a5d..1ad269e57 100644 --- a/zaqar/common/configs.py +++ b/zaqar/common/configs.py @@ -58,6 +58,8 @@ _NOTIFICATION_OPTIONS = ( cfg.StrOpt('smtp_command', default='/usr/sbin/sendmail -t -oi', help=('The command of smtp to send email. The format is ' '"command_name arg1 arg2".')), + cfg.IntOpt('max_notifier_workers', default=10, + help='The max amount of the notification workers.') ) _NOTIFICATION_GROUP = 'notification' diff --git a/zaqar/notification/notifier.py b/zaqar/notification/notifier.py index 605d2fd8d..b5a1d66d9 100644 --- a/zaqar/notification/notifier.py +++ b/zaqar/notification/notifier.py @@ -32,8 +32,8 @@ class NotifierDriver(object): def __init__(self, *args, **kwargs): self.subscription_controller = kwargs.get('subscription_controller') - # TODO(flwang): Make the max_workers configurable - self.executor = futurist.ThreadPoolExecutor(max_workers=10) + max_workers = kwargs.get('max_notifier_workers', 10) + self.executor = futurist.ThreadPoolExecutor(max_workers=max_workers) def post(self, queue_name, messages, client_uuid, project=None): """Send messages to the subscribers.""" diff --git a/zaqar/storage/pipeline.py b/zaqar/storage/pipeline.py index d7df0fa42..15e3417d7 100644 --- a/zaqar/storage/pipeline.py +++ b/zaqar/storage/pipeline.py @@ -148,7 +148,9 @@ class DataDriver(base.DataDriverBase): stages = _get_builtin_entry_points('message', self._storage, self.control_driver) kwargs = {'subscription_controller': - self._storage.subscription_controller} + self._storage.subscription_controller, + 'max_notifier_workers': + self.conf.notification.max_notifier_workers} stages.extend(_get_storage_pipeline('message', self.conf, **kwargs)) stages.append(self._storage.message_controller) return common.Pipeline(stages) diff --git a/zaqar/tests/base.py b/zaqar/tests/base.py index 09d701a6a..436fc5447 100644 --- a/zaqar/tests/base.py +++ b/zaqar/tests/base.py @@ -56,6 +56,8 @@ class TestBase(testtools.TestCase): self.conf.register_opts(configs._GENERAL_OPTIONS) self.conf.register_opts(configs._DRIVER_OPTIONS, group=configs._DRIVER_GROUP) + self.conf.register_opts(configs._NOTIFICATION_OPTIONS, + group=configs._NOTIFICATION_GROUP) self.mongodb_url = os.environ.get('ZAQAR_TEST_MONGODB_URL', 'mongodb://127.0.0.1:27017')