Adding support for configuring number of async worker processes

Adding new config parameter to control number of async worker
processes. Also removing existing parameter 'workers' as its not
used and was currently defined under DEFAULT config section.

Change-Id: I04af9d012ca86227171eecebdbf43999dd667ac5
Closes-Bug: #1519159
This commit is contained in:
Arun Kant 2016-01-18 17:06:18 -08:00
parent 715eb91ae2
commit 2694881dec
4 changed files with 36 additions and 8 deletions

View File

@ -63,7 +63,8 @@ def main():
service.launch(
CONF,
server.TaskServer()
server.TaskServer(),
workers=CONF.queue.asynchronous_workers
).wait()
except RuntimeError as e:
fail(1, e)

View File

@ -93,6 +93,8 @@ queue_opts = [
help=u._('Version of tasks invoked via queue')),
cfg.StrOpt('server_name', default='barbican.queue',
help=u._('Server name for RPC task processing server')),
cfg.IntOpt('asynchronous_workers', default=1,
help=u._('Number of asynchronous worker processes')),
]
ks_queue_opt_group = cfg.OptGroup(name=KS_NOTIFICATIONS_GRP_NAME,

View File

@ -15,6 +15,8 @@
import mock
from barbican.cmd import retry_scheduler
from barbican.cmd import worker
from barbican.tests.queue import test_keystone_listener
from barbican.tests import utils
@ -50,3 +52,29 @@ class WhenInvokingRetryServiceCommand(utils.BaseTestCase):
retry_scheduler.main()
self.assertEqual(1, mock_sys_exit.call_count)
class WhenInvokingWorkerCommand(test_keystone_listener.UtilMixin,
utils.BaseTestCase):
"""Test the asynchronous worker functionality."""
def setUp(self):
super(WhenInvokingWorkerCommand, self).setUp()
@mock.patch('barbican.queue.init')
@mock.patch('barbican.queue.get_server')
@mock.patch('oslo_service.service.launch')
def test_should_launch_service(
self,
mock_service_launch,
mock_queue_task_server,
mock_queue_init):
self.opt_in_group('queue', asynchronous_workers=3)
worker.main()
self.assertEqual(1, mock_queue_init.call_count)
self.assertEqual(1, mock_service_launch.call_count)
# check keyword argument for number of worker matches
workers_kwarg = {'workers': 3}
self.assertEqual(workers_kwarg, mock_service_launch.call_args[1])

View File

@ -82,13 +82,6 @@ default_limit_paging = 10
# Maximum page size for the 'limit' paging URL parameter.
max_limit_paging = 100
# Number of Barbican API worker processes to start.
# On machines with more than one CPU increasing this value
# may improve performance (especially if using SSL with
# compression turned on). It is typically recommended to set
# this value to the number of CPUs present on your machine.
workers = 1
# Role used to identify an authenticated user as administrator
#admin_role = admin
@ -169,6 +162,10 @@ version = '1.1'
# Server name for RPC service
server_name = 'barbican.queue'
# Number of asynchronous worker processes.
# When greater than 1, then that many additional worker processes are
# created for asynchronous worker functionality.
asynchronous_workers = 1
# ================= Retry/Scheduler Options ==========================