diff options
authorThomas Morin <>2017-06-02 15:36:43 +0200
committerKevin Benton <>2017-06-09 22:25:13 +0000
commita08aa3bf2f567d4d0a5678d470cc3a3aec382d74 (patch)
parent0d866f1743fd551633617c77e8cb65953ad9d680 (diff)
l3_ha_mode: call bulk _populate_mtu_and_subnets_for_ports
Based on the observation that a call to sync_routers can be very slow (minutes) on some setup, and that profiling data show that a significant amount of time is spent in many individual calls of _process_sync_ha_data to _populate_mtu_and_subnets_for_ports for a single interface, this change refactors _process_sync_ha_data to call _populate_mtu_and_subnets_for_ports only once on a list of interfaces instead of <n> times. Said otherwise: - before: O(#routers) SQL queries (one per network of an HA interface of a router) - after : O(1) SQL queries (on the set of networks with an HA interface on a router) A basic test shows a drastic improvements, from minutes to around one second, in the processing of a sync_routers call with 256 routers. Change-Id: I3a00c8fbb245ab3b6d93bdaa97f3435570992791 Related-Bug: 1692971
Notes (review): Code-Review+2: Armando Migliaccio <> Code-Review+2: Brian Haley <> Code-Review+2: Kevin Benton <> Workflow+1: Kevin Benton <> Code-Review+1: Tuan Luong-Anh <> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 12 Jun 2017 10:16:35 +0000 Reviewed-on: Project: openstack/neutron Branch: refs/heads/stable/ocata
1 files changed, 4 insertions, 1 deletions
diff --git a/neutron/db/ b/neutron/db/
index 0f21ebc..7871f1f 100644
--- a/neutron/db/
+++ b/neutron/db/
@@ -644,10 +644,13 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
644 router[constants.HA_INTERFACE_KEY] = port_dict 644 router[constants.HA_INTERFACE_KEY] = port_dict
645 router[n_const.HA_ROUTER_STATE_KEY] = binding.state 645 router[n_const.HA_ROUTER_STATE_KEY] = binding.state
646 646
647 interfaces = []
647 for router in routers_dict.values(): 648 for router in routers_dict.values():
648 interface = router.get(constants.HA_INTERFACE_KEY) 649 interface = router.get(constants.HA_INTERFACE_KEY)
649 if interface: 650 if interface:
650 self._populate_mtu_and_subnets_for_ports(context, [interface]) 651 interfaces.append(interface)
653 self._populate_mtu_and_subnets_for_ports(context, interfaces)
651 654
652 # If this is a DVR+HA router, but the agent is question is in 'dvr' 655 # If this is a DVR+HA router, but the agent is question is in 'dvr'
653 # mode (as opposed to 'dvr_snat'), then we want to always return it 656 # mode (as opposed to 'dvr_snat'), then we want to always return it