From 0bd4a04afb35d7e60b34b8a1aaab45b7805cad15 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Mon, 3 Sep 2012 22:23:24 +1000 Subject: Speed up creating floating ips. Previously, we would make two separate DB calls for each floating ip we created in floating_ip_bulk_create. This was just a little slow (several hours to create a /16). This patch speeds up floating ip creation just a little: $ time bin/nova-manage floating create --ip_range=10.250.0.0/16 real 0m48.766s user 0m34.342s sys 0m1.984s Resolves bug 1023560. Change-Id: Ie3663440d414b102111178899db0c571769edba8 --- nova/db/sqlalchemy/api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 106c8b8ed..797516ac9 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -716,10 +716,21 @@ def floating_ip_allocate_address(context, project_id, pool): @require_context def floating_ip_bulk_create(context, ips): + existing_ips = {} + for floating in _floating_ip_get_all(context).all(): + existing_ips[floating['address']] = floating + session = get_session() with session.begin(): for ip in ips: - floating_ip_create(context, ip, session) + addr = ip['address'] + if (addr in existing_ips and + ip.get('id') != existing_ips[addr]['id']): + raise exception.FloatingIpExists(**dict(existing_ips[addr])) + + model = models.FloatingIp() + model.update(ip) + session.add(model) @require_context -- cgit