From b97b24856f611998ade3ac7390074dc02b880b19 Mon Sep 17 00:00:00 2001 From: John Eckersberg Date: Wed, 28 Mar 2018 15:01:36 -0400 Subject: [PATCH] Use eventlet-aware threading events For the gory details behind this, see: https://bugzilla.redhat.com/show_bug.cgi?id=1384183 In summary, if you use threading.Event on python2 with eventlet, it unnecessarily spams system calls to epoll_wait and burns a *lot* of CPU cycles by constantly context-switching. I added eventletutils.Event to oslo_utils a while back to intelligently use the eventlet Event object when eventlet is being used, and to fall back to the threading one otherwise. So just use that and it will do the right thing. Depends-On: https://review.openstack.org/#/c/558879/ Change-Id: I6ca0d0fc2a2ff393bab502a5f705fb0d63c32c6b --- lower-constraints.txt | 2 +- mistral/rpc/kombu/kombu_listener.py | 3 ++- mistral/rpc/kombu/kombu_server.py | 5 +++-- requirements.txt | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 8cda2555e..394729ad4 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -80,7 +80,7 @@ oslo.middleware==3.31.0 oslo.policy==1.30.0 oslo.serialization==2.18.0 oslo.service==1.24.0 -oslo.utils==3.33.0 +oslo.utils==3.37.0 oslosphinx==4.7.0 oslotest==3.2.0 osprofiler==1.4.0 diff --git a/mistral/rpc/kombu/kombu_listener.py b/mistral/rpc/kombu/kombu_listener.py index 157c0cd2d..d44aa4537 100644 --- a/mistral/rpc/kombu/kombu_listener.py +++ b/mistral/rpc/kombu/kombu_listener.py @@ -19,6 +19,7 @@ import six import threading from oslo_log import log as logging +from oslo_utils import eventletutils from mistral.rpc.kombu import base as kombu_base @@ -34,7 +35,7 @@ class KombuRPCListener(ConsumerMixin): self._thread = None self.connection = six.next(self._connections) - self.ready = threading.Event() + self.ready = eventletutils.Event() def add_listener(self, correlation_id): self._results[correlation_id] = six.moves.queue.Queue() diff --git a/mistral/rpc/kombu/kombu_server.py b/mistral/rpc/kombu/kombu_server.py index 51c556d02..3ac474255 100644 --- a/mistral/rpc/kombu/kombu_server.py +++ b/mistral/rpc/kombu/kombu_server.py @@ -20,6 +20,7 @@ import time import kombu from oslo_config import cfg from oslo_log import log as logging +from oslo_utils import eventletutils from stevedore import driver from mistral import context as auth_ctx @@ -68,8 +69,8 @@ class KombuRPCServer(rpc_base.RPCServer, kombu_base.Base): self.routing_key = self.topic self.channel = None self.conn = None - self._running = threading.Event() - self._stopped = threading.Event() + self._running = eventletutils.Event() + self._stopped = eventletutils.Event() self.endpoints = [] self._worker = None self._thread = None diff --git a/requirements.txt b/requirements.txt index f9a7d8455..de9ffb3d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,7 @@ oslo.i18n>=3.15.3 # Apache-2.0 oslo.messaging>=5.29.0 # Apache-2.0 oslo.middleware>=3.31.0 # Apache-2.0 oslo.policy>=1.30.0 # Apache-2.0 -oslo.utils>=3.33.0 # Apache-2.0 +oslo.utils>=3.37.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.service!=1.28.1,>=1.24.0 # Apache-2.0