From 16d8819891c4bef58760c62c30aa2b68868087b9 Mon Sep 17 00:00:00 2001
From: vsaienko <vsaienko@mirantis.com>
Date: Thu, 3 Mar 2016 01:07:33 +0200
Subject: [PATCH] Update resources only for specific node during deletion.

At the moment during Nova instance termination resources are
updated for all Ironic nodes. As result with high number of nodes,
removing N instances initiates N x M requests, where M is the total
number of nodes. This commit allows to update resources per specific
node on termination.

Depends-On: Iffad4a6ab1aaa5fea591c19f6d330dc861c5675d

Change-Id: Ib54741c8564e18f23c4f50bed190dfc66db7ba76
Closes-Bug: #1552446
---
 ironic/nova/compute/manager.py                       | 12 +++++++-----
 ...e-deletion-update-resources-53862e48ab658f77.yaml |  5 +++++
 2 files changed, 12 insertions(+), 5 deletions(-)
 create mode 100644 releasenotes/notes/node-deletion-update-resources-53862e48ab658f77.yaml

diff --git a/ironic/nova/compute/manager.py b/ironic/nova/compute/manager.py
index 0e36bf054b..c2bf47a3fe 100644
--- a/ironic/nova/compute/manager.py
+++ b/ironic/nova/compute/manager.py
@@ -81,13 +81,15 @@ class ClusteredComputeManager(manager.ComputeManager):
             pass
 
     @lockutils.synchronized(CCM_SEMAPHORE, 'ironic-')
-    def _update_resources(self):
-        """Update our resources
+    def _update_resources(self, node_uuid):
+        """Update the specified node resource
 
-        Updates the resources while protecting against a race on
+        Updates the resources for instance while protecting against a race on
         self._resource_tracker_dict.
+        :param node_uuid: UUID of the Ironic node to update resources for.
         """
-        self.update_available_resource(nova.context.get_admin_context())
+        self.update_available_resource_for_node(
+            nova.context.get_admin_context(), node_uuid)
 
     def terminate_instance(self, context, instance, bdms, reservations):
         """Terminate an instance on a node.
@@ -100,4 +102,4 @@ class ClusteredComputeManager(manager.ComputeManager):
                                                                 instance,
                                                                 bdms,
                                                                 reservations)
-        self._update_resources()
+        self._update_resources(instance.node)
diff --git a/releasenotes/notes/node-deletion-update-resources-53862e48ab658f77.yaml b/releasenotes/notes/node-deletion-update-resources-53862e48ab658f77.yaml
new file mode 100644
index 0000000000..5f523588dc
--- /dev/null
+++ b/releasenotes/notes/node-deletion-update-resources-53862e48ab658f77.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+  - Fixed performance issue for 'ironic.nova.compute.ClusteredComputeManager'
+    when during Nova instance termination resources were updated for all
+    Nova hypervisors.