From 3c96ce9158924476d88c815d0889d6d52ff62c76 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 8 Aug 2018 16:22:53 +0100 Subject: [PATCH] [placement] Avoid rp.get_by_uuid in allocation_candidates We already have a fully loaded resource provider object in the loop, so we don't need to create another one. Doing so has a very large performance impact, especially when there are many resource providers in the collection of summaries (which will be true in a large and sparsely used cloud). The code which creates the summaries used here as a data source has the same expensive use of get_by_uuid in a loop. That will be fixed in a separate patch. Existing functional tests cover this code. Change-Id: I6068db78240c33a1dcefedc0c94e76740fd8d6e2 Partial-Bug: #1786055 --- nova/api/openstack/placement/objects/resource_provider.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nova/api/openstack/placement/objects/resource_provider.py b/nova/api/openstack/placement/objects/resource_provider.py index 851f9719e4f9..ac6d4993902c 100644 --- a/nova/api/openstack/placement/objects/resource_provider.py +++ b/nova/api/openstack/placement/objects/resource_provider.py @@ -3516,11 +3516,9 @@ def _alloc_candidates_multiple_providers(ctx, requested_resources, for rp_id, root_id, rc_id in rp_tuples: rp_summary = summaries[rp_id] - rp_uuid = rp_summary.resource_provider.uuid tree_dict[root_id][rc_id].append( AllocationRequestResource( - ctx, resource_provider=ResourceProvider.get_by_uuid(ctx, - rp_uuid), + ctx, resource_provider=rp_summary.resource_provider, resource_class=_RC_CACHE.string_from_id(rc_id), amount=requested_resources[rc_id]))