From ea1e0b6e815c02373b2fe6ddb96cbaa214fad308 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 2 Jul 2018 15:28:20 -0700 Subject: [PATCH] Avoid join and yield per and just iterate This seems to have (in our testing) made everything go smoothly, even with playbooks with 10000 tasks. Before this we were having glitches with the wrong number of tasks and out of memory; which no longer happens now (at least with regards to playbook results). Change-Id: I5fe571a528f677c474abade5e266290e6e66c860 --- ara/views/reports.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/ara/views/reports.py b/ara/views/reports.py index bc0d5ad3..88201ba3 100644 --- a/ara/views/reports.py +++ b/ara/views/reports.py @@ -174,10 +174,9 @@ def ajax_records(playbook): @reports.route('/reports/ajax/results/.txt') def ajax_results(playbook): - task_results = (models.TaskResult.query - .join(models.Task) - .filter(models.Task.playbook_id == playbook)) - if not utils.fast_count(task_results): + tasks_in_playbook = models.Task.query.filter( + models.Task.playbook_id == playbook) + if not utils.fast_count(tasks_in_playbook): abort(404) jinja = current_app.jinja_env @@ -190,19 +189,23 @@ def ajax_results(playbook): results['data'] = list() log.debug('Loading results') - log.debug('* If this part eats your RAM, please help us fix this :)') - for result in task_results.yield_per(YIELD_PER): - name = name_cell.render(tags=result.task.tags, name=result.task.name) - host = result.host.name - action = action_link.render(file=result.task.file, - lineno=result.task.lineno, - action=result.task.action) - elapsed = time.render(time=result.task.offset_from_playbook) - duration = time.render(time=result.duration) - status = task_status_link.render(id=result.id, - derived_status=result.derived_status) - - results['data'].append([name, host, action, elapsed, duration, status]) + for task in tasks_in_playbook: + task_results = task.task_results + for result in task_results: + name = name_cell.render(tags=result.task.tags, + name=result.task.name) + host = result.host.name + action = action_link.render(file=result.task.file, + lineno=result.task.lineno, + action=result.task.action) + elapsed = time.render(time=result.task.offset_from_playbook) + duration = time.render(time=result.duration) + status = task_status_link.render( + id=result.id, derived_status=result.derived_status) + results['data'].append([name, host, action, + elapsed, duration, status]) + del task_results + del task log.debug('%s results loaded' % len(results['data'])) return jsonify(results)