diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-01-30 16:23:04 -0800 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-02-02 08:47:45 -0800 |
| commit | 655ae2e9394dd91e70a52cc504dfab8f4431e2fa (patch) | |
| tree | e5ed8f65f2c288b5a4ea0b3e97e24d398a7eaf8a /nova/db | |
| parent | 922f81c18bfbfd3ca8a0b5b1edf59723f7d366af (diff) | |
| download | nova-655ae2e9394dd91e70a52cc504dfab8f4431e2fa.tar.gz nova-655ae2e9394dd91e70a52cc504dfab8f4431e2fa.tar.xz nova-655ae2e9394dd91e70a52cc504dfab8f4431e2fa.zip | |
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
Diffstat (limited to 'nova/db')
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 3 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/models.py | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 393e1a03c..b41dfa625 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -627,6 +627,7 @@ def certificate_get_all_by_user_and_project(context, user_id, project_id): def floating_ip_get(context, id): result = model_query(context, models.FloatingIp, project_only=True).\ filter_by(id=id).\ + options(joinedload_all('fixed_ip.instance')).\ first() if not result: @@ -841,6 +842,7 @@ def floating_ip_get_all_by_project(context, project_id): return _floating_ip_get_all(context).\ filter_by(project_id=project_id).\ filter_by(auto_assigned=False).\ + options(joinedload_all('fixed_ip.instance')).\ all() @@ -858,6 +860,7 @@ def _floating_ip_get_by_address(context, address, session=None): result = model_query(context, models.FloatingIp, session=session).\ filter_by(address=address).\ + options(joinedload_all('fixed_ip.instance')).\ first() if not result: 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): |
