From d99a5fc9d7ccb3feb699be346723cd84da780544 Mon Sep 17 00:00:00 2001 From: Omer Date: Fri, 20 Jun 2025 10:01:46 +0000 Subject: [PATCH] Migrate API service to use native threading This commit performs the first service migration from eventlet to standard python threading, focusing on the `designate-api` service. The API service main entrypoint (designate/cmd/api.py) now explicitly initializes oslo_service threading backend. It will be removed when the migration is complete. Change-Id: Ic15de389f01a42f8dc918511e9a60df1449f1bed Signed-off-by: Omer --- designate/cmd/{eventlet => threading}/api.py | 5 ++++- designate/conf/api.py | 4 ++-- designate/network_api/base.py | 5 +---- designate/tests/unit/cmd/test_cmd.py | 5 ++++- .../notes/api-threading-migration-7b0b9c045fd9496d.yaml | 8 ++++++++ setup.cfg | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) rename designate/cmd/{eventlet => threading}/api.py (95%) create mode 100644 releasenotes/notes/api-threading-migration-7b0b9c045fd9496d.yaml diff --git a/designate/cmd/eventlet/api.py b/designate/cmd/threading/api.py similarity index 95% rename from designate/cmd/eventlet/api.py rename to designate/cmd/threading/api.py index 9eb085e65..fe9f0a407 100644 --- a/designate/cmd/eventlet/api.py +++ b/designate/cmd/threading/api.py @@ -41,4 +41,7 @@ def main(): heartbeat = heartbeat_emitter.get_heartbeat_emitter(server.service_name) service.serve(server, workers=CONF['service:api'].workers) heartbeat.start() - service.wait() + try: + service.wait() + finally: + heartbeat.stop() diff --git a/designate/conf/api.py b/designate/conf/api.py index 0447da61e..afb8e5d71 100644 --- a/designate/conf/api.py +++ b/designate/conf/api.py @@ -23,8 +23,8 @@ API_GROUP = cfg.OptGroup( API_OPTS = [ cfg.IntOpt('workers', help='Number of api worker processes to spawn'), - cfg.IntOpt('threads', default=1000, - help='Number of api greenthreads to spawn'), + cfg.IntOpt('threads', default=100, + help='Number of api threads to spawn'), cfg.BoolOpt('enable_host_header', default=True, help='Enable host request headers'), cfg.StrOpt('api_base_uri', default='http://127.0.0.1:9001/', diff --git a/designate/network_api/base.py b/designate/network_api/base.py index 4192baddc..d8e34c78c 100644 --- a/designate/network_api/base.py +++ b/designate/network_api/base.py @@ -13,7 +13,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import eventlet.patcher +from dns import reversename from oslo_log import log as logging import designate.conf @@ -23,9 +23,6 @@ from designate.plugin import DriverPlugin CONF = designate.conf.CONF LOG = logging.getLogger(__name__) -# NOTE(kiall): This is a workaround for bug #1424621, a broken reimplementation -# of eventlet's 0.17.0 monkey patching of dnspython. -reversename = eventlet.patcher.original('dns.reversename') class NetworkAPI(DriverPlugin): diff --git a/designate/tests/unit/cmd/test_cmd.py b/designate/tests/unit/cmd/test_cmd.py index fc0cd40f2..4961053a5 100644 --- a/designate/tests/unit/cmd/test_cmd.py +++ b/designate/tests/unit/cmd/test_cmd.py @@ -14,7 +14,6 @@ from unittest import mock from oslo_config import fixture as cfg_fixture import oslotest.base -from designate.cmd.eventlet import api from designate.cmd.eventlet import central from designate.cmd.eventlet import mdns from designate.cmd.eventlet import producer @@ -26,6 +25,10 @@ import designate.conf CONF = designate.conf.CONF +with mock.patch('oslo_service.backend.init_backend'): + from designate.cmd.threading import api + + @mock.patch('designate.service.wait') @mock.patch('designate.service.serve') @mock.patch('designate.heartbeat_emitter.get_heartbeat_emitter') diff --git a/releasenotes/notes/api-threading-migration-7b0b9c045fd9496d.yaml b/releasenotes/notes/api-threading-migration-7b0b9c045fd9496d.yaml new file mode 100644 index 000000000..48e8128ae --- /dev/null +++ b/releasenotes/notes/api-threading-migration-7b0b9c045fd9496d.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - | + The designate-api service has been migrated from eventlet to use + native Python threading. + + The default number of API threads has been reduced from 1000 to 100 + to reflect the change from eventlet greenthreads to native OS threads. diff --git a/setup.cfg b/setup.cfg index 69df7ee18..29696b65b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -53,7 +53,7 @@ oslo.policy.enforcer = console_scripts = designate-rootwrap = oslo_rootwrap.cmd:main - designate-api = designate.cmd.eventlet.api:main + designate-api = designate.cmd.threading.api:main designate-central = designate.cmd.eventlet.central:main designate-manage = designate.cmd.eventlet.manage:main designate-mdns = designate.cmd.eventlet.mdns:main