A random startup delay option for minions

This allows minions to spread out the load to the master if a large number
of them start up at once.
This commit is contained in:
Mike Place 2017-03-02 16:42:45 -07:00 committed by C. R. Oldham
parent a48ecc4a5c
commit 8ab321f934
3 changed files with 25 additions and 0 deletions

View file

@ -193,6 +193,15 @@
# The wait-time will be a random number of seconds between 0 and the defined value.
#random_reauth_delay: 60
# To avoid overloading a master when many minions startup at once, a randomized
# delay may be set to tell the minions to wait before connecting to the master.
# This value is the number of seconds to choose from for a random number. For
# example, setting this value to 60 will choose a random number of seconds to delay
# on startup between zero seconds and sixty seconds. Setting to '0' will disable
# this feature.
#random_startup_delay: 0
# When waiting for a master to accept the minion's public key, salt will
# continuously attempt to reconnect until successful. This is the timeout value,
# in seconds, for each individual attempt. After this timeout expires, the minion

View file

@ -724,6 +724,12 @@ VALID_OPTS = {
# The logfile location for salt-key
'key_logfile': str,
# The upper bound for the random number of seconds that a minion should
# delay when starting in up before it connects to a master. This can be
# used to mitigate a thundering-herd scenario when many minions start up
# at once and attempt to all connect immediately to the master
'random_startup_delay': int,
# The source location for the winrepo sls files
# (used by win_pkg.py, minion only)
'winrepo_source_dir': str,
@ -984,6 +990,7 @@ DEFAULT_MINION_OPTS = {
'renderer': 'yaml_jinja',
'renderer_whitelist': [],
'renderer_blacklist': [],
'random_startup_delay': 0,
'failhard': False,
'autoload_dynamic_modules': True,
'environment': None,

View file

@ -11,6 +11,7 @@ import copy
import time
import types
import signal
import random
import fnmatch
import logging
import threading
@ -967,6 +968,14 @@ class Minion(MinionBase):
self.opts['grains'] = salt.loader.grains(opts)
log.info('Creating minion process manager')
if self.opts['random_startup_delay']:
sleep_time = random.randint(0, self.opts['random_startup_delay'])
log.info('Minion sleeping for {0} seconds due to configured '
'startup_delay between 0 and {1} seconds'.format(sleep_time,
self.opts['random_startup_delay']))
time.sleep(sleep_time)
self.process_manager = ProcessManager(name='MinionProcessManager')
self.io_loop.spawn_callback(self.process_manager.run, async=True)
# We don't have the proxy setup yet, so we can't start engines