From: Salvatore Orlando Date: Fri, 28 Aug 2015 15:55:42 +0000 (-0700) Subject: Reservations: Don't count usage if resource is unlimited X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3c9482eb78b8a1e459ea9876a3b9a977690fce0d;p=openstack-build%2Fneutron-build.git Reservations: Don't count usage if resource is unlimited If a resource is unlimited (ie: limit<0) then there is no need to verify headroom for it. This also means that there no need for counting it; therefore it is possible to save some DB operations by skipping the count phase. Change-Id: Ibe9ca8a1c29fb8ba12df187c25f8f9515968a54d Related-blueprint: better-quotas --- diff --git a/neutron/db/quota/driver.py b/neutron/db/quota/driver.py index 5358960be..c9249950f 100644 --- a/neutron/db/quota/driver.py +++ b/neutron/db/quota/driver.py @@ -153,6 +153,20 @@ class DbQuotaDriver(object): # to a single node will be avaialable. requested_resources = deltas.keys() with db_api.autonested_transaction(context.session): + # get_tenant_quotes needs in input a dictionary mapping resource + # name to BaseResosurce instances so that the default quota can be + # retrieved + current_limits = self.get_tenant_quotas( + context, resources, tenant_id) + unlimited_resources = set([resource for (resource, limit) in + current_limits.items() if limit < 0]) + # Do not even bother counting resources and calculating headroom + # for resources with unlimited quota + LOG.debug(("Resources %s have unlimited quota limit. It is not " + "required to calculated headroom "), + ",".join(unlimited_resources)) + requested_resources = (set(requested_resources) - + unlimited_resources) # Gather current usage information # TODO(salv-orlando): calling count() for every resource triggers # multiple queries on quota usage. This should be improved, however @@ -164,11 +178,6 @@ class DbQuotaDriver(object): (resource, resources[resource].count( context, plugin, tenant_id, resync_usage=False)) for resource in requested_resources) - # get_tenant_quotes needs in inout a dictionary mapping resource - # name to BaseResosurce instances so that the default quota can be - # retrieved - current_limits = self.get_tenant_quotas( - context, resources, tenant_id) # Adjust for expired reservations. Apparently it is cheaper than # querying everytime for active reservations and counting overall # quantity of resources reserved @@ -179,13 +188,6 @@ class DbQuotaDriver(object): for resource in requested_resources: expired_reservations = expired_deltas.get(resource, 0) total_usage = current_usages[resource] - expired_reservations - # A negative quota limit means infinite - if current_limits[resource] < 0: - LOG.debug(("Resource %(resource)s has unlimited quota " - "limit. It is possible to allocate %(delta)s " - "items."), {'resource': resource, - 'delta': deltas[resource]}) - continue res_headroom = current_limits[resource] - total_usage LOG.debug(("Attempting to reserve %(delta)d items for " "resource %(resource)s. Total usage: %(total)d; "