Skip to content

Commit

Permalink
Use compute_api.get_all in affinity filters.
Browse files Browse the repository at this point in the history
Updates the affinity filters so they make a single compute API
call to lookup instance host information rather than single
lookups for each UUID.

This resolves a potential performance issue which can cause a
scheduler to hang while processing requests which contain large numbers
of UUID's in the scheduler_hints.

Fixes LP Bug #1017795.

Change-Id: I30f434faf109058573ee41c4a6abce2e48939e8d
  • Loading branch information
dprince committed Jul 11, 2012
1 parent b91d2fc commit 034762e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions nova/scheduler/filters/affinity_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ class AffinityFilter(filters.BaseHostFilter):
def __init__(self):
self.compute_api = compute.API()

def _affinity_host(self, context, instance_id):
return self.compute_api.get(context, instance_id)['host']
def _all_hosts(self, context):
all_hosts = {}
for instance in self.compute_api.get_all(context):
all_hosts[instance['uuid']] = instance['host']
return all_hosts


class DifferentHostFilter(AffinityFilter):
Expand All @@ -41,8 +44,9 @@ def host_passes(self, host_state, filter_properties):
if isinstance(affinity_uuids, basestring):
affinity_uuids = [affinity_uuids]
if affinity_uuids:
all_hosts = self._all_hosts(context)
return not any([i for i in affinity_uuids
if self._affinity_host(context, i) == me])
if all_hosts.get(i) == me])
# With no different_host key
return True

Expand All @@ -61,9 +65,10 @@ def host_passes(self, host_state, filter_properties):
if isinstance(affinity_uuids, basestring):
affinity_uuids = [affinity_uuids]
if affinity_uuids:
all_hosts = self._all_hosts(context)
return any([i for i
in affinity_uuids
if self._affinity_host(context, i) == me])
if all_hosts.get(i) == me])
# With no same_host key
return True

Expand Down

0 comments on commit 034762e

Please sign in to comment.