summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangbo <wangbo_bupt@163.com>2016-12-26 13:50:03 +0800
committerwangbo <wangbo_bupt@163.com>2017-01-09 20:25:55 +0800
commitb462a3b8cd0ccbf374dd140315ec1c431a8546be (patch)
treea836e8e92b932249927cdb4d1289c0343c9f1560
parentc0091a40534460933ea385d054d5c6e85f9b1c82 (diff)
Support magnum-api multiple process workers
Multiple process workers support for magnum-api. Adds new option 'workers' to group [api] of magnum.conf. Change-Id: I0e8327ada6926602d577d1f36d384dd49426c7ee Implements: blueprint magnum-multiple-process-workers
Notes
Notes (review): Code-Review+1: yatin <yatin.karel@nectechnologies.in> Code-Review+2: Adrian Otto <adrian.otto@rackspace.com> Code-Review+1: guo yunxian <yunxian.guo@easystack.cn> Code-Review+1: Thomas Bechtold <tbechtold@suse.com> Code-Review+1: Vijendar Komalla <vijendar.komalla@rackspace.com> Code-Review+2: Eli Qiao <qiaoliyong@gmail.com> Workflow+1: Eli Qiao <qiaoliyong@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 15 Feb 2017 08:37:27 +0000 Reviewed-on: https://review.openstack.org/416433 Project: openstack/magnum Branch: refs/heads/master
-rw-r--r--magnum/cmd/api.py8
-rw-r--r--magnum/conf/api.py5
-rw-r--r--magnum/tests/unit/cmd/test_api.py25
3 files changed, 35 insertions, 3 deletions
diff --git a/magnum/cmd/api.py b/magnum/cmd/api.py
index 41e54d1..92d7863 100644
--- a/magnum/cmd/api.py
+++ b/magnum/cmd/api.py
@@ -17,6 +17,7 @@
17import os 17import os
18import sys 18import sys
19 19
20from oslo_concurrency import processutils
20from oslo_log import log as logging 21from oslo_log import log as logging
21from oslo_reports import guru_meditation_report as gmr 22from oslo_reports import guru_meditation_report as gmr
22from werkzeug import serving 23from werkzeug import serving
@@ -75,5 +76,10 @@ def main():
75 LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'), 76 LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'),
76 dict(proto="https" if use_ssl else "http", host=host, port=port)) 77 dict(proto="https" if use_ssl else "http", host=host, port=port))
77 78
78 serving.run_simple(host, port, app, 79 workers = CONF.api.workers
80 if not workers:
81 workers = processutils.get_worker_count()
82 LOG.info(_LI('Server will handle each request in a new process up to'
83 ' %s concurrent processes'), workers)
84 serving.run_simple(host, port, app, processes=workers,
79 ssl_context=_get_ssl_configs(use_ssl)) 85 ssl_context=_get_ssl_configs(use_ssl))
diff --git a/magnum/conf/api.py b/magnum/conf/api.py
index 11756c9..0df0da8 100644
--- a/magnum/conf/api.py
+++ b/magnum/conf/api.py
@@ -39,7 +39,10 @@ api_service_opts = [
39 "effect. "), 39 "effect. "),
40 cfg.BoolOpt('enabled_ssl', 40 cfg.BoolOpt('enabled_ssl',
41 default=False, 41 default=False,
42 help='Enable SSL Magnum API service') 42 help='Enable SSL Magnum API service'),
43 cfg.IntOpt('workers',
44 help='The maximum number of magnum-api processes to '
45 'fork and run. Default to number of CPUs on the host.')
43] 46]
44 47
45 48
diff --git a/magnum/tests/unit/cmd/test_api.py b/magnum/tests/unit/cmd/test_api.py
index e6ce096..ea55ead 100644
--- a/magnum/tests/unit/cmd/test_api.py
+++ b/magnum/tests/unit/cmd/test_api.py
@@ -14,6 +14,8 @@
14 14
15import mock 15import mock
16 16
17from oslo_concurrency import processutils
18
17from magnum.cmd import api 19from magnum.cmd import api
18from magnum.tests import base 20from magnum.tests import base
19 21
@@ -32,9 +34,28 @@ class TestMagnumAPI(base.TestCase):
32 app = mock_app.load_app.return_value 34 app = mock_app.load_app.return_value
33 mock_prep.assert_called_once_with(mock.ANY) 35 mock_prep.assert_called_once_with(mock.ANY)
34 mock_app.load_app.assert_called_once_with() 36 mock_app.load_app.assert_called_once_with()
37 workers = processutils.get_worker_count()
38 mock_run.assert_called_once_with(base.CONF.api.host,
39 base.CONF.api.port,
40 app, processes=workers,
41 ssl_context=None)
42
43 @mock.patch('werkzeug.serving.run_simple')
44 @mock.patch.object(api, 'api_app')
45 @mock.patch('magnum.common.service.prepare_service')
46 def test_api_http_config_workers(self, mock_prep, mock_app,
47 mock_run, mock_base):
48 fake_workers = 8
49 self.config(workers=fake_workers, group='api')
50 api.main()
51
52 app = mock_app.load_app.return_value
53 mock_prep.assert_called_once_with(mock.ANY)
54 mock_app.load_app.assert_called_once_with()
35 mock_run.assert_called_once_with(base.CONF.api.host, 55 mock_run.assert_called_once_with(base.CONF.api.host,
36 base.CONF.api.port, 56 base.CONF.api.port,
37 app, ssl_context=None) 57 app, processes=fake_workers,
58 ssl_context=None)
38 59
39 @mock.patch('os.path.exists') 60 @mock.patch('os.path.exists')
40 @mock.patch('werkzeug.serving.run_simple') 61 @mock.patch('werkzeug.serving.run_simple')
@@ -91,6 +112,8 @@ class TestMagnumAPI(base.TestCase):
91 mock_app.load_app.assert_called_once_with() 112 mock_app.load_app.assert_called_once_with()
92 mock_exist.assert_has_calls([mock.call('tmp_crt'), 113 mock_exist.assert_has_calls([mock.call('tmp_crt'),
93 mock.call('tmp_key')]) 114 mock.call('tmp_key')])
115 workers = processutils.get_worker_count()
94 mock_run.assert_called_once_with(base.CONF.api.host, 116 mock_run.assert_called_once_with(base.CONF.api.host,
95 base.CONF.api.port, app, 117 base.CONF.api.port, app,
118 processes=workers,
96 ssl_context=('tmp_crt', 'tmp_key')) 119 ssl_context=('tmp_crt', 'tmp_key'))