diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index a94576b80d..13785f2097 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -207,7 +207,10 @@ Number of Glance worker processes to start. Provide a non-negative integer value to set the number of child process workers to service requests. By default, the number of CPUs -available is set as the value for ``workers``. +available is set as the value for ``workers`` limited to 8. For +example if the processor count is 6, 6 workers will be used, if the +processor count is 24 only 8 workers will be used. The limit will only +apply to the default value, if 24 workers is configured, 24 is used. Each worker process is made to listen on the port set in the configuration file and contains a greenthread pool of size 1000. @@ -332,8 +335,10 @@ except ImportError: def get_num_workers(): """Return the configured number of workers.""" if CONF.workers is None: - # None implies the number of CPUs - return processutils.get_worker_count() + # None implies the number of CPUs limited to 8 + # See Launchpad bug #1748916 and the config help text + workers = processutils.get_worker_count() + return workers if workers < 8 else 8 return CONF.workers diff --git a/glance/tests/unit/common/test_wsgi.py b/glance/tests/unit/common/test_wsgi.py index 0f4c5ad566..710d94807e 100644 --- a/glance/tests/unit/common/test_wsgi.py +++ b/glance/tests/unit/common/test_wsgi.py @@ -604,7 +604,7 @@ class ServerTest(test_utils.BaseTestCase): socket_timeout=900) def test_number_of_workers(self): - """Ensure the default number of workers matches num cpus.""" + """Ensure the number of workers matches num cpus limited to 8.""" def pid(): i = 1 while True: @@ -612,12 +612,30 @@ class ServerTest(test_utils.BaseTestCase): yield i with mock.patch.object(os, 'fork') as mock_fork: + with mock.patch('oslo_concurrency.processutils.get_worker_count', + return_value=4): + mock_fork.side_effect = pid + server = wsgi.Server() + server.configure = mock.Mock() + fake_application = "fake-application" + server.start(fake_application, None) + self.assertEqual(4, len(server.children)) + with mock.patch('oslo_concurrency.processutils.get_worker_count', + return_value=24): + mock_fork.side_effect = pid + server = wsgi.Server() + server.configure = mock.Mock() + fake_application = "fake-application" + server.start(fake_application, None) + self.assertEqual(8, len(server.children)) mock_fork.side_effect = pid server = wsgi.Server() server.configure = mock.Mock() fake_application = "fake-application" server.start(fake_application, None) - self.assertEqual(processutils.get_worker_count(), + cpus = processutils.get_worker_count() + expected_workers = cpus if cpus < 8 else 8 + self.assertEqual(expected_workers, len(server.children))