Add new host_pinned strategy (#44586)

The 'free' strategy still attempts to do all hosts per task before going to the next, it just doesn't wait for slow hosts,
This strategy processes each host as fast as possible to the end of the play before trying to process another host in the pool.
This commit is contained in:
Brian Coca 2018-08-23 20:16:32 -04:00 committed by GitHub
commit 9cc56981b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 0 deletions

View file

@ -58,6 +58,10 @@ class StrategyModule(StrategyBase):
return [host for host in notified_hosts
if host in self._flushed_hosts and self._flushed_hosts[host]]
def __init__(self, tqm):
super(StrategyModule, self).__init__(tqm)
self._host_pinned = False
def run(self, iterator, play_context):
'''
The "free" strategy is a bit more complex, in that it allows tasks to
@ -77,6 +81,9 @@ class StrategyModule(StrategyBase):
result = self._tqm.RUN_OK
# start with all workers being counted as being free
workers_free = len(self._workers)
work_to_do = True
while work_to_do and not self._tqm._terminated:
@ -167,10 +174,18 @@ class StrategyModule(StrategyBase):
"as tasks are executed independently on each host")
self._tqm.send_callback('v2_playbook_on_task_start', task, is_conditional=False)
self._queue_task(host, task, task_vars, play_context)
# each task is counted as a worker being busy
workers_free -= 1
del task_vars
else:
display.debug("%s is blocked, skipping for now" % host_name)
# all workers have tasks to do (and the current host isn't done with the play).
# loop back to starting host and break out
if self._host_pinned and workers_free == 0 and work_to_do:
last_host = starting_host
break
# move on to the next host and make sure we
# haven't gone past the end of our hosts list
last_host += 1
@ -184,6 +199,9 @@ class StrategyModule(StrategyBase):
results = self._process_pending_results(iterator)
host_results.extend(results)
# each result is counted as a worker being free again
workers_free += len(results)
self.update_active_connections(results)
try: