From d94d6d6892291b195649d1a9666cc6b49b39a7a4 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Sat, 18 Jul 2015 14:32:34 +0200 Subject: [PATCH] Allows to change defaults opts This change introduces to possibility for the consumer application to change the default oslo.messaging config options. Same API interface as oslo.db have been taken. The first option is executor_thread_pool_size. This option was called rpc_thread_pool_size, but because it's used by notification and rpc 'executor_thread_pool_size' looks a better name. Changing executor_thread_pool_size default will be useful for ceilometer the default of 64 is really to small to consume many notifications at once for batching them. When is clearly sufficient for rpc stuffs. Change-Id: Iea0d7a72e38d27c600403c815258aa5eee0d0c8c --- oslo_messaging/_drivers/impl_zmq.py | 3 ++- .../_executors/impl_pooledexecutor.py | 8 +++++--- oslo_messaging/opts.py | 20 +++++++++++++++++++ oslo_messaging/tests/test_opts.py | 8 ++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/oslo_messaging/_drivers/impl_zmq.py b/oslo_messaging/_drivers/impl_zmq.py index 6108e9519..e11383661 100644 --- a/oslo_messaging/_drivers/impl_zmq.py +++ b/oslo_messaging/_drivers/impl_zmq.py @@ -465,7 +465,8 @@ class ZmqBaseReactor(ConsumerBase): self.sockets = [] self.subscribe = {} - self.pool = eventlet.greenpool.GreenPool(conf.rpc_thread_pool_size) + self.pool = eventlet.greenpool.GreenPool( + conf.executor_thread_pool_size) def register(self, proxy, in_addr, zmq_type_in, in_bind=True, subscribe=None): diff --git a/oslo_messaging/_executors/impl_pooledexecutor.py b/oslo_messaging/_executors/impl_pooledexecutor.py index c9531acff..68743368c 100644 --- a/oslo_messaging/_executors/impl_pooledexecutor.py +++ b/oslo_messaging/_executors/impl_pooledexecutor.py @@ -25,9 +25,10 @@ from oslo_utils import excutils from oslo_messaging._executors import base _pool_opts = [ - cfg.IntOpt('rpc_thread_pool_size', + cfg.IntOpt('executor_thread_pool_size', default=64, - help='Size of RPC thread pool.'), + deprecated_name="rpc_thread_pool_size", + help='Size of executor thread pool.'), ] @@ -103,7 +104,8 @@ class PooledExecutor(base.ExecutorBase): def start(self): if self._executor is None: - self._executor = self._executor_cls(self.conf.rpc_thread_pool_size) + self._executor = self._executor_cls( + self.conf.executor_thread_pool_size) self._tombstone.clear() if self._poller is None or not self._poller.is_alive(): self._poller = self._thread_cls(target=self._runner) diff --git a/oslo_messaging/opts.py b/oslo_messaging/opts.py index 1f065b5ea..267b7ec16 100644 --- a/oslo_messaging/opts.py +++ b/oslo_messaging/opts.py @@ -76,3 +76,23 @@ def list_opts(): :returns: a list of (group_name, opts) tuples """ return [(g, copy.deepcopy(o)) for g, o in _opts] + + +def set_defaults(conf, executor_thread_pool_size=None): + """Set defaults for configuration variables. + + Overrides default options values. + + :param conf: Config instance specified to set default options in it. Using + of instances instead of a global config object prevents conflicts between + options declaration. + :type conf: oslo.config.cfg.ConfigOpts instance. + + :keyword executor_thread_pool_size: Size of executor thread pool. + :type executor_thread_pool_size: int + :default executor_thread_pool_size: None + + """ + if executor_thread_pool_size is not None: + conf.set_default('executor_thread_pool_size', + executor_thread_pool_size) diff --git a/oslo_messaging/tests/test_opts.py b/oslo_messaging/tests/test_opts.py index d1c75a0bc..5e4f241f9 100644 --- a/oslo_messaging/tests/test_opts.py +++ b/oslo_messaging/tests/test_opts.py @@ -15,6 +15,9 @@ import stevedore import testtools +import mock + +from oslo_messaging._executors import impl_thread try: from oslo_messaging import opts except ImportError: @@ -55,3 +58,8 @@ class OptsTestCase(test_utils.BaseTestCase): self.assertIsNotNone(result) self._test_list_opts(result) + + def test_defaults(self): + impl_thread.ThreadExecutor(self.conf, mock.Mock(), mock.Mock()) + opts.set_defaults(self.conf, executor_thread_pool_size=100) + self.assertEqual(100, self.conf.executor_thread_pool_size)