Просмотр исходного кода

Remove redundant RPC client instantiations during event handling.

Nashwan Azhari 5 лет назад
Родитель
Сommit
8e88f62f02
2 измененных файлов с 8 добавлено и 2 удалено
  1. 4 1
      coriolis/conductor/rpc/client.py
  2. 4 1
      coriolis/minion_manager/rpc/client.py

+ 4 - 1
coriolis/conductor/rpc/client.py

@@ -443,13 +443,16 @@ class ConductorTaskRpcEventHandler(events.BaseEventHandler):
     def __init__(self, ctxt, task_id):
     def __init__(self, ctxt, task_id):
         self._ctxt = ctxt
         self._ctxt = ctxt
         self._task_id = task_id
         self._task_id = task_id
+        self._rpc_conductor_client_instance = None
 
 
     @property
     @property
     def _rpc_conductor_client(self):
     def _rpc_conductor_client(self):
         # NOTE(aznashwan): it is unsafe to fork processes with pre-instantiated
         # NOTE(aznashwan): it is unsafe to fork processes with pre-instantiated
         # oslo_messaging clients as the underlying eventlet thread queues will
         # oslo_messaging clients as the underlying eventlet thread queues will
         # be invalidated.
         # be invalidated.
-        return ConductorClient()
+        if self._rpc_conductor_client_instance is None:
+            self._rpc_conductor_client_instance = ConductorClient()
+        return self._rpc_conductor_client_instance
 
 
     @classmethod
     @classmethod
     def get_progress_update_identifier(self, progress_update):
     def get_progress_update_identifier(self, progress_update):

+ 4 - 1
coriolis/minion_manager/rpc/client.py

@@ -177,13 +177,16 @@ class MinionManagerPoolRpcEventHandler(events.BaseEventHandler):
     def __init__(self, ctxt, pool_id):
     def __init__(self, ctxt, pool_id):
         self._ctxt = ctxt
         self._ctxt = ctxt
         self._pool_id = pool_id
         self._pool_id = pool_id
+        self._rpc_minion_manager_client_instance = None
 
 
     @property
     @property
     def _rpc_minion_manager_client(self):
     def _rpc_minion_manager_client(self):
         # NOTE(aznashwan): it is unsafe to fork processes with pre-instantiated
         # NOTE(aznashwan): it is unsafe to fork processes with pre-instantiated
         # oslo_messaging clients as the underlying eventlet thread queues will
         # oslo_messaging clients as the underlying eventlet thread queues will
         # be invalidated.
         # be invalidated.
-        return MinionManagerClient()
+        if self._rpc_minion_manager_client_instance is None:
+            self._rpc_minion_manager_client_instance = MinionManagerClient()
+        return self._rpc_minion_manager_client_instance
 
 
     @classmethod
     @classmethod
     def get_progress_update_identifier(self, progress_update):
     def get_progress_update_identifier(self, progress_update):