yahoo-eng-team team mailing list archive
-
yahoo-eng-team team
-
Mailing list archive
-
Message #78601
[Bug 1830234] Re: InstanceGroup.get_hosts() uses inefficient DB queries
The inefficient query goes back to Icehouse when the
InstanceGroup.get_hosts() method was introduced:
https://review.opendev.org/#/c/77786/
So we can at least backport the #1 fix above to stable/ocata.
** Also affects: nova/rocky
Importance: Undecided
Status: New
** Also affects: nova/ocata
Importance: Undecided
Status: New
** Also affects: nova/stein
Importance: Undecided
Status: New
** Also affects: nova/queens
Importance: Undecided
Status: New
** Also affects: nova/pike
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1830234
Title:
InstanceGroup.get_hosts() uses inefficient DB queries
Status in OpenStack Compute (nova):
Triaged
Status in OpenStack Compute (nova) ocata series:
New
Status in OpenStack Compute (nova) pike series:
New
Status in OpenStack Compute (nova) queens series:
New
Status in OpenStack Compute (nova) rocky series:
New
Status in OpenStack Compute (nova) stein series:
New
Bug description:
The InstanceGroup.get_hosts() method is pretty inefficient when
pulling instances out of the database here:
https://github.com/openstack/nova/blob/c7e9e667426a6d88d396a59cb40d30763a3265f9/nova/objects/instance_group.py#L500
because that by default is going to join on the following tables:
https://github.com/openstack/nova/blob/c7e9e667426a6d88d396a59cb40d30763a3265f9/nova/db/sqlalchemy/api.py#L2098
if columns_to_join is None:
columns_to_join_new = ['info_cache', 'security_groups']
manual_joins = ['metadata', 'system_metadata']
And then just turn around and only use the instance.host value:
https://github.com/openstack/nova/blob/c7e9e667426a6d88d396a59cb40d30763a3265f9/nova/objects/instance_group.py#L502
return list(set([instance.host for instance in instances
if instance.host]))
We should be:
1. Avoiding those unnecessary joins by passing expected_attrs=[] which
is a simple backportable fix.
2. Write a new DB API method which would get the set of distinct
instances.host values for the list of instance uuids where the
instances.host value is not None, so I think:
SELECT host FROM instances WHERE host IS NOT NULL AND deleted == 0 AND
uuid IN ($instance_uuids) GROUP BY instances.host;
That way we let the DB query do the work and we don't have to load up
all of the additional instances fields we don't care about.
The DB API optimization would likely need to be a remotable method
because InstanceGroup.get_hosts() is calling in the late affinity
check ComputeManager._validate_instance_group_policy() method in the
nova-compute service (and because InstanceGroup.get_hosts() is
remotable itself).
To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1830234/+subscriptions
References