diff --git a/doc/source/admin/concurrency.rst b/doc/source/admin/concurrency.rst index e99bc4b2e0cf..52b12fa7cf5a 100644 --- a/doc/source/admin/concurrency.rst +++ b/doc/source/admin/concurrency.rst @@ -21,14 +21,21 @@ up support for the native threading mode. Selecting concurrency mode for a service ---------------------------------------- -Nova still uses Eventlet by default, but allows switching services to native -threading mode at service startup via setting the environment variable -``OS_NOVA_DISABLE_EVENTLET_PATCHING=true``. +Since nova 33.0.0 (2026.1 Gazpacho) the nova-scheduler, nova-api, and +nova-metadata are using native threading by default. The rest of the +services are using eventlet by default in this release. The concurrency mode +can be configured via setting the environment variable +``OS_NOVA_DISABLE_EVENTLET_PATCHING``. Setting that variable to ``true`` +requests the native threading mode while setting it to ``false`` requests the +eventlet mode. If the variable is not set the above default is applied. .. note:: - Since nova 32.0.0 (2025.2 Flamingo) the nova-scheduler, nova-metadata, - nova-api, and nova-conductor can be switched to native threading mode. + Since nova 32.0.0 (2025.2 Flamingo) the nova-scheduler, nova-metadata, and + nova-api can be switched to native threading mode. + + Since nova 33.0.0 (2026.1 Gazpacho) also the nova-conductor can be switched + to native threading mode. Tunables for the native threading mode diff --git a/nova/cmd/scheduler.py b/nova/cmd/scheduler.py index 62a5c9750c54..95323cff149c 100644 --- a/nova/cmd/scheduler.py +++ b/nova/cmd/scheduler.py @@ -16,7 +16,7 @@ """Starter script for Nova Scheduler.""" # autopep8: off -from nova import monkey_patch; monkey_patch.patch() # noqa +from nova import monkey_patch; monkey_patch.patch(backend='threading') # noqa # autopep8: on import sys diff --git a/nova/monkey_patch.py b/nova/monkey_patch.py index f97dd8ae32f2..58893df7bbcb 100644 --- a/nova/monkey_patch.py +++ b/nova/monkey_patch.py @@ -72,10 +72,29 @@ def _monkey_patch(): return True -def patch(): - if (os.environ.get('OS_NOVA_DISABLE_EVENTLET_PATCHING', '').lower() - not in ('1', 'true', 'yes')): +def patch(backend='eventlet'): + """Apply eventlet monkey patching according to environment. + :param backend: Defines the default backend if not explicitly set via + the environment. If 'eventlet', then monkey patch if environment + variable is not defined. If 'threading', then do not monkey patch if + environment variable is not defined. Any other value results in a + ValueError. If the environment variable is defined this parameter + is ignored. + """ + if backend not in ('eventlet', 'threading'): + raise ValueError( + "the backend can only be 'eventlet' or 'threading'") + + env = os.environ.get('OS_NOVA_DISABLE_EVENTLET_PATCHING', '').lower() + if env == '': + should_patch = (backend == 'eventlet') + elif env in ('1', 'true', 'yes'): + should_patch = False + else: + should_patch = True + + if should_patch: if _monkey_patch(): global MONKEY_PATCHED MONKEY_PATCHED = True diff --git a/nova/tests/unit/test_utils.py b/nova/tests/unit/test_utils.py index 63b0dbad97c7..8a5d12060243 100644 --- a/nova/tests/unit/test_utils.py +++ b/nova/tests/unit/test_utils.py @@ -1691,3 +1691,17 @@ class OsloServiceBackendSelectionTestCase(test.NoDBTestCase): "OS_NOVA_DISABLE_EVENTLET_PATCHING set to 'true', but then the " "service tried to call eventlet.monkey_patch(). This is a bug.", str(ex)) + + @mock.patch('oslo_service.backend.init_backend') + def test_threading_selected_by_default(self, init_backend): + with mock.patch.dict(os.environ): + del os.environ["OS_NOVA_DISABLE_EVENTLET_PATCHING"] + monkey_patch.patch(backend='threading') + + init_backend.assert_called_once_with( + oslo_backend.BackendType.THREADING) + + def test_invalid_default_backend(self): + ex = self.assertRaises(ValueError, monkey_patch.patch, backend='foo') + self.assertEqual( + "the backend can only be 'eventlet' or 'threading'", str(ex)) diff --git a/nova/wsgi/metadata.py b/nova/wsgi/metadata.py index f70598233a96..cd7817c2ef76 100644 --- a/nova/wsgi/metadata.py +++ b/nova/wsgi/metadata.py @@ -12,7 +12,7 @@ """WSGI application entry-point for Nova Metadata API.""" # autopep8: off -from nova import monkey_patch ; monkey_patch.patch() # noqa +from nova import monkey_patch; monkey_patch.patch(backend='threading') # noqa # autopep8: on import threading diff --git a/nova/wsgi/osapi_compute.py b/nova/wsgi/osapi_compute.py index 00e5f6fcba0e..53c759e42d83 100644 --- a/nova/wsgi/osapi_compute.py +++ b/nova/wsgi/osapi_compute.py @@ -12,7 +12,7 @@ """WSGI application entry-point for Nova Compute API.""" # autopep8: off -from nova import monkey_patch ; monkey_patch.patch() # noqa +from nova import monkey_patch; monkey_patch.patch(backend='threading') # noqa # autopep8: on import threading diff --git a/releasenotes/notes/threading-by-default-sch-api-meta-d2534ce9c7b69d8a.yaml b/releasenotes/notes/threading-by-default-sch-api-meta-d2534ce9c7b69d8a.yaml new file mode 100644 index 000000000000..f4dd831ed70b --- /dev/null +++ b/releasenotes/notes/threading-by-default-sch-api-meta-d2534ce9c7b69d8a.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + The default concurrency mode is now switched from eventlet to native + threading for nova-scheduler, nova-api, and nova-metadata services. + The concurrency mode can still be switched back to eventlet if needed. + Please read the + `concurrency `__ + guide for more details. diff --git a/tox.ini b/tox.ini index 115c86d2cc1a..505a0bc834e0 100644 --- a/tox.ini +++ b/tox.ini @@ -56,12 +56,14 @@ commands = env TEST_OSPROFILER=1 stestr run --combine --no-discover 'nova.tests.unit.test_profiler' stestr slowest -[testenv:{unit,py3,py310,py311,py312}] +[testenv:{unit,py3,py310,py311,py312,py313}] setenv = {[testenv]setenv} # we do not have any greenlet leaks in unit tests so enforce that # by making greenlet leaks a failure. NOVA_RAISE_ON_GREENLET_LEAK=True +# run the test with eventlet + OS_NOVA_DISABLE_EVENTLET_PATCHING=False [testenv:py312-threading] setenv = @@ -81,7 +83,7 @@ commands = stestr run {posargs} --exclude-list /tmp/exclude.txt stestr slowest -[testenv:functional{,-py310,-py311,-py312}] +[testenv:functional{,-py310,-py311,-py312,-py313}] description = Run functional tests. setenv = @@ -89,6 +91,8 @@ setenv = # we do not have any greenlet leaks in functional tests so enforce that # by making greenlet leaks a failure. NOVA_RAISE_ON_GREENLET_LEAK=True +# run the test with eventlet + OS_NOVA_DISABLE_EVENTLET_PATCHING=False # As nova functional tests import the PlacementFixture from the placement # repository these tests are, by default, set up to run with openstack-placement # from pypi. In the gate, Zuul will use the installed version of placement (stable @@ -208,6 +212,8 @@ commands = setenv = {[testenv]setenv} PYTHON=coverage run --source nova --parallel-mode +# run the test with eventlet + OS_NOVA_DISABLE_EVENTLET_PATCHING=False extras = commands = coverage erase @@ -244,6 +250,9 @@ commands = sphinx-build -W --keep-going -b html -j auto doc/source doc/build/html # Test the redirects. This must run after the main docs build whereto doc/build/html/.htaccess doc/test/redirect-tests.txt +setenv = + OS_NOVA_DISABLE_EVENTLET_PATCHING=False + [testenv:pdf-docs] description =

AltStyle によって変換されたページ (->オリジナル) /