Make monkey patch work in uWSGI mode
There was a eventlet.monkey_patch [1] when we launch a nova process(like nova-api, nova-compute), but it's invalid under the uwsgi mode. But there are concurrency requirements in the api service, such as, when listing instances cross multiple cells we're using greenthreads and oslo.db does a time.sleep to allow switching greenthreads [2]. So, in this patch we add the monkey_patch in the uwsgi application setup and refactor the monkey patching to use common code. [1] https://github.com/openstack/nova/blob/233ea58/nova/cmd/__init__.py#L26 [2] https://github.com/openstack/oslo.db/blob/9c66959/oslo_db/sqlalchemy/engines.py#L51 Closes-bug: #1787331 Change-Id: Ie7bf5d012e2ccbcd63c262ddaf739782afcdaf56
This commit is contained in:
parent
a761429103
commit
23ba1c6906
|
@ -23,11 +23,13 @@ from nova import context
|
|||
from nova import exception
|
||||
from nova import objects
|
||||
from nova import service
|
||||
from nova import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
CONFIG_FILES = ['api-paste.ini', 'nova.conf']
|
||||
|
||||
utils.monkey_patch()
|
||||
objects.register_all()
|
||||
|
||||
|
||||
|
|
|
@ -13,20 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import eventlet
|
||||
from oslo_utils import importutils
|
||||
from six.moves import reload_module
|
||||
from nova import utils
|
||||
|
||||
from nova import debugger
|
||||
|
||||
if debugger.enabled():
|
||||
# turn off thread patching to enable the remote debugger
|
||||
eventlet.monkey_patch(os=False, thread=False)
|
||||
else:
|
||||
eventlet.monkey_patch(os=False)
|
||||
|
||||
# NOTE(rgerganov): oslo.context is storing a global thread-local variable
|
||||
# which keeps the request context for the current thread. If oslo.context is
|
||||
# imported before calling monkey_patch(), then this thread-local won't be
|
||||
# green. To workaround this, reload the module after calling monkey_patch()
|
||||
reload_module(importutils.import_module('oslo_context.context'))
|
||||
utils.monkey_patch()
|
||||
|
|
|
@ -48,8 +48,10 @@ from oslo_utils import timeutils
|
|||
from oslo_utils import units
|
||||
import six
|
||||
from six.moves import range
|
||||
from six.moves import reload_module
|
||||
|
||||
import nova.conf
|
||||
from nova import debugger
|
||||
from nova import exception
|
||||
from nova.i18n import _, _LE, _LI, _LW
|
||||
import nova.network
|
||||
|
@ -1296,3 +1298,18 @@ def generate_hostid(host, project_id):
|
|||
sha_hash = hashlib.sha224(data)
|
||||
return sha_hash.hexdigest()
|
||||
return ""
|
||||
|
||||
|
||||
def monkey_patch():
|
||||
if debugger.enabled():
|
||||
# turn off thread patching to enable the remote debugger
|
||||
eventlet.monkey_patch(os=False, thread=False)
|
||||
else:
|
||||
eventlet.monkey_patch(os=False)
|
||||
|
||||
# NOTE(rgerganov): oslo.context is storing a global thread-local variable
|
||||
# which keeps the request context for the current thread. If oslo.context
|
||||
# is imported before calling monkey_patch(), then this thread-local won't
|
||||
# be green. To workaround this, reload the module after calling
|
||||
# monkey_patch()
|
||||
reload_module(importutils.import_module('oslo_context.context'))
|
||||
|
|
Loading…
Reference in New Issue