Fixing up performance

This commit is contained in:
James Cammarata
2015-11-04 11:26:06 -05:00
parent c64ac90560
commit 63c47fb271
10 changed files with 62 additions and 26 deletions

View File

@@ -21,6 +21,7 @@ __metaclass__ = type
from ansible.compat.six.moves import queue
import json
import multiprocessing
import os
import signal
@@ -43,6 +44,7 @@ from ansible.executor.task_executor import TaskExecutor
from ansible.executor.task_result import TaskResult
from ansible.playbook.handler import Handler
from ansible.playbook.task import Task
from ansible.vars.unsafe_proxy import AnsibleJSONUnsafeDecoder
from ansible.utils.debug import debug
@@ -59,9 +61,9 @@ class WorkerProcess(multiprocessing.Process):
def __init__(self, tqm, main_q, rslt_q, loader):
# takes a task queue manager as the sole param:
self._main_q = main_q
self._rslt_q = rslt_q
self._loader = loader
self._main_q = main_q
self._rslt_q = rslt_q
self._loader = loader
# dupe stdin, if we have one
self._new_stdin = sys.stdin
@@ -97,9 +99,9 @@ class WorkerProcess(multiprocessing.Process):
while True:
task = None
try:
debug("waiting for a message...")
(host, task, basedir, job_vars, play_context, shared_loader_obj) = self._main_q.get()
debug("there's work to be done!")
debug("got a task/handler to work on: %s" % task)
debug("there's work to be done! got a task/handler to work on: %s" % task)
# because the task queue manager starts workers (forks) before the
# playbook is loaded, set the basedir of the loader inherted by
@@ -114,7 +116,15 @@ class WorkerProcess(multiprocessing.Process):
# execute the task and build a TaskResult from the result
debug("running TaskExecutor() for %s/%s" % (host, task))
executor_result = TaskExecutor(host, task, job_vars, play_context, self._new_stdin, self._loader, shared_loader_obj).run()
executor_result = TaskExecutor(
host,
task,
job_vars,
play_context,
self._new_stdin,
self._loader,
shared_loader_obj,
).run()
debug("done running TaskExecutor() for %s/%s" % (host, task))
task_result = TaskResult(host, task, executor_result)

View File

@@ -156,7 +156,8 @@ class TaskExecutor:
# create a copy of the job vars here so that we can modify
# them temporarily without changing them too early for other
# parts of the code that might still need a pristine version
vars_copy = self._job_vars.copy()
#vars_copy = self._job_vars.copy()
vars_copy = self._job_vars
# now we update them with the play context vars
self._play_context.update_vars(vars_copy)
@@ -196,7 +197,8 @@ class TaskExecutor:
# make copies of the job vars and task so we can add the item to
# the variables and re-validate the task with the item variable
task_vars = self._job_vars.copy()
#task_vars = self._job_vars.copy()
task_vars = self._job_vars
items = self._squash_items(items, task_vars)
for item in items:
@@ -357,7 +359,8 @@ class TaskExecutor:
# make a copy of the job vars here, in case we need to update them
# with the registered variable value later on when testing conditions
vars_copy = variables.copy()
#vars_copy = variables.copy()
vars_copy = variables
self._display.debug("starting attempt loop")
result = None

View File

@@ -96,7 +96,7 @@ class TaskQueueManager:
self._workers = []
def _initialize_workers(self, num):
for i in range(num):
for i in xrange(num_workers):
main_q = multiprocessing.Queue()
rslt_q = multiprocessing.Queue()