Optimize mistral queries for 'get_task_executions'

During workflow executions there are a lot of calls of function
'find_task_executions_by_name' from lookup_utils. This function
internally calls 'get_task_executions' with two filters: name and
workflow_execution_id.

To optimize this call it's reasonable to add a composite db index
by these two fields.

Another optimization is to explicitely disable sorting by 'created_at',
because it's unnecessary in this particulat case.

Change-Id: Ife150a384575cc4ad2fe45dc093816b48268df6f
This commit is contained in:
Mike Fedosin 2017-10-12 11:52:48 +03:00 committed by Renat Akhmerov
parent e5cd0ad2e9
commit 8a81089785
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,34 @@
# Copyright 2017 OpenStack Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Add database indices
Revision ID: 024
Revises: 023
Create Date: 2017-10-11 15:23:04.904251
"""
# revision identifiers, used by Alembic.
revision = '024'
down_revision = '023'
from alembic import op
def upgrade():
op.create_index('task_executions_v2_workflow_execution_id_name',
'task_executions_v2',
['workflow_execution_id', 'name'])

View File

@ -345,6 +345,11 @@ sa.Index(
TaskExecution.workflow_execution_id
)
sa.Index(
'%s_workflow_execution_id_name' % TaskExecution.__tablename__,
TaskExecution.workflow_execution_id, TaskExecution.name
)
# Other objects.

View File

@ -67,7 +67,8 @@ def find_task_executions_by_name(wf_ex_id, task_name):
t_execs = db_api.get_task_executions(
workflow_execution_id=wf_ex_id,
name=task_name
name=task_name,
sort_keys=[] # disable sorting
)
# We can cache only finished tasks because they won't change.