diff options
| author | Michael Still <mikal@stillhq.com> | 2012-09-04 20:46:00 +1000 |
|---|---|---|
| committer | Michael Still <mikal@stillhq.com> | 2012-09-09 18:59:51 +1000 |
| commit | 5339141f04bf3ce470677e5fc3800ce4ac3fc0ae (patch) | |
| tree | 4c4b41b90dfe1f324c4a1093abb0812896e2b401 /nova | |
| parent | f348875724d2b46dedc7f090d4f8cf78b194a15a (diff) | |
Improve floating IP delete speed.
This is similar to the change to improve bulk creation speed. Before:
./bin/nova-manage floating delete --ip_range 10.250.0.0/16
337.20user 10.22system 44:07.10elapsed 13%CPU (0avgtext+0avgdata 119536maxresident)k
400inputs+0outputs (4major+11704minor)pagefaults 0swaps
After:
./bin/nova-manage floating delete --ip_range 10.250.0.0/16
6.95user 0.16system 1:04.04elapsed 11%CPU (0avgtext+0avgdata 120016maxresident)k
0inputs+0outputs (0major+11750minor)pagefaults 0swaps
Resolves bug 1023560.
Change-Id: If4f23222025cae88576f469022e0f7d907c9c4fa
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/db/api.py | 5 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 34 |
2 files changed, 37 insertions, 2 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index 46d0305ef..785944d14 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -274,6 +274,11 @@ def floating_ip_bulk_create(context, ips): return IMPL.floating_ip_bulk_create(context, ips) +def floating_ip_bulk_destroy(context, ips): + """Destroy a lot of floating ips from the values dictionary.""" + return IMPL.floating_ip_bulk_destroy(context, ips) + + def floating_ip_create(context, values): """Create a floating ip from the values dictionary.""" return IMPL.floating_ip_create(context, values) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 341b0d332..183bc0b36 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -734,6 +734,35 @@ def floating_ip_bulk_create(context, ips): session.add(model) +def _ip_range_splitter(ips): + """Yields blocks of IPs no more than 256 elements long.""" + out = [] + count = 0 + for ip in ips: + out.append(ip['address']) + count += 1 + + if count > 255: + yield out + out = [] + count = 0 + + if out: + yield out + + +@require_context +def floating_ip_bulk_destroy(context, ips): + session = get_session() + with session.begin(): + for ip_block in _ip_range_splitter(ips): + model_query(context, models.FloatingIp).\ + filter(models.FloatingIp.address.in_(ip_block)).\ + update({'deleted': True, + 'deleted_at': timeutils.utcnow()}, + synchronize_session='fetch') + + @require_context def floating_ip_create(context, values, session=None): if not session: @@ -838,8 +867,9 @@ def floating_ip_set_auto_assigned(context, address): floating_ip_ref.save(session=session) -def _floating_ip_get_all(context): - return model_query(context, models.FloatingIp, read_deleted="no") +def _floating_ip_get_all(context, session=None): + return model_query(context, models.FloatingIp, read_deleted="no", + session=session) @require_admin_context |
