Merge "Enable bulk updates for the dnsmasq"

This commit is contained in:
Zuul 2020-02-03 04:03:29 +00:00 committed by Gerrit Code Review
commit e17464ad11
3 changed files with 38 additions and 1 deletions

View File

@ -115,6 +115,7 @@ class DhcpAgent(manager.Manager):
self._pool_size = DHCP_PROCESS_GREENLET_MIN
self._pool = eventlet.GreenPool(size=self._pool_size)
self._queue = queue.ResourceProcessingQueue()
self._network_bulk_allocations = {}
def init_host(self):
self.sync_state()
@ -144,11 +145,27 @@ class DhcpAgent(manager.Manager):
self.periodic_resync()
self.start_ready_ports_loop()
eventlet.spawn_n(self._process_loop)
if self.conf.bulk_reload_interval:
eventlet.spawn_n(self._reload_bulk_allocations)
def _reload_bulk_allocations(self):
while True:
for network_id in self._network_bulk_allocations.keys():
network = self.cache.get_network_by_id(network_id)
self.call_driver('bulk_reload_allocations', network)
del self._network_bulk_allocations[network_id]
eventlet.greenthread.sleep(self.conf.bulk_reload_interval)
def call_driver(self, action, network, **action_kwargs):
"""Invoke an action on a DHCP driver instance."""
LOG.debug('Calling driver for network: %(net)s action: %(action)s',
{'net': network.id, 'action': action})
if self.conf.bulk_reload_interval and action == 'reload_allocations':
LOG.debug("Call deferred to bulk load")
self._network_bulk_allocations[network.id] = True
return True
if action == 'bulk_reload_allocations':
action = 'reload_allocations'
try:
# the Driver expects something that is duck typed similar to
# the base models.

View File

@ -68,7 +68,13 @@ DHCP_AGENT_OPTS = [
cfg.IntOpt('num_sync_threads', default=4,
help=_('Number of threads to use during sync process. '
'Should not exceed connection pool size configured on '
'server.'))
'server.')),
cfg.IntOpt('bulk_reload_interval', default=0, min=0,
help=_('Time to sleep between reloading the DHCP allocations. '
'This will only be invoked if the value is not 0. '
'If a network has N updates in X seconds then '
'we will reload once with the port changes in the X '
'seconds and not N times.')),
]
DHCP_OPTS = [

View File

@ -0,0 +1,14 @@
---
features:
- By default the dnsmasq agent is restarted for every
port created, deleted or updated. When there are
many port changes on the same network it can and will
take a very long time for all of the port changes to
be realised. This enhancement adds in a new
configuration variable that will enable bulk updates.
This means that the dnsmasq will only be restarted once
in a period and not N times.
The new option 'bulk_reload_interval' indicates how
often the agent should be reloaded. The default value
is 0 which means that the original functionality is the
default.