From 655ae2e9394dd91e70a52cc504dfab8f4431e2fa Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 30 Jan 2013 16:23:04 -0800 Subject: Optimize floating ip list to make one db query Currently the floating ip code will make 2 db queries for every single associated floating ip when list is called. This adds a couple of joins in the db layer to avoid having to make so many calls. This dramatically improves floating-ip-list. On a simple one node test the time dropped from 2.35 seconds down to 0.5 seconds for a list with 10 associated floating ips. Part of blueprint optimize-nova-network Change-Id: I0571013393b2dbad42c15e690c7783d5ceecaeb2 --- nova/db/sqlalchemy/models.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'nova/db/sqlalchemy/models.py') diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index fd8348678..b4c680ac0 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -724,7 +724,14 @@ class FixedIp(BASE, NovaBase): foreign_keys=network_id, primaryjoin='and_(' 'FixedIp.network_id == Network.id,' - 'FixedIp.deleted == 0)') + 'FixedIp.deleted == 0,' + 'Network.deleted == 0)') + instance = relationship(Instance, + foreign_keys=instance_uuid, + primaryjoin='and_(' + 'FixedIp.instance_uuid == Instance.uuid,' + 'FixedIp.deleted == 0,' + 'Instance.deleted == 0)') class FloatingIp(BASE, NovaBase): @@ -738,6 +745,13 @@ class FloatingIp(BASE, NovaBase): auto_assigned = Column(Boolean, default=False, nullable=False) pool = Column(String(255)) interface = Column(String(255)) + fixed_ip = relationship(FixedIp, + backref=backref('floating_ips'), + foreign_keys=fixed_ip_id, + primaryjoin='and_(' + 'FloatingIp.fixed_ip_id == FixedIp.id,' + 'FloatingIp.deleted == 0,' + 'FixedIp.deleted == 0)') class DNSDomain(BASE, NovaBase): -- cgit