Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sql): Optimize executions #4804

Merged
merged 8 commits into from
Dec 19, 2024

Conversation

kirangodishala
Copy link
Contributor

@kirangodishala kirangodishala commented Nov 24, 2024

This PR improves performance when using sql as the backend by optimizing the way the results are obtained for the api call /applications/{application}/pipelines?expand=false&limit=2 frequently initiated by deck.

Deck makes that call to Gate. Gate further forwards that call to Orca, specifically to /v2/applications/{application}/pipelines endpoint.

Orca calls front50 to get the pipeline and strategy config ids and then merges them. Then for each id in the merged list, it queries its own db (SQL) to handle the query parameters, such as limit=2 and filter by statuses. It is observed that these db operations are taking longer times and this PR fixes the slowness by optimizing the queries to the db.

Refactored TaskController to support externalized config properties

Optimize getPipelinesForApplication() by reducing the number of relevant pipeline config ids to query

Further optimize getPipelinesForApplication() by processing multiple pipeline config ids at a time and multi-threading each config id batch

Breaking changes:

These configuration properties

tasks:
   days-of-execution-history:  
   number-of-old-pipeline-executions-to-include: 

are replaced by the below configuration along with few more newly added ones:

tasks:
   controller:
      days-of-execution-history: 
      number-of-old-pipeline-executions-to-include: 

      optimize-execution-retrieval: <boolean>
      max-execution-retrieval-threads:
      max-number-of-pipeline-executions-to-process: 
      execution-retrieval-timeout-seconds: 

@kirangodishala kirangodishala changed the title Optimize executions feat(sql): Optimize executions Nov 25, 2024
orca-web/orca-web.gradle Outdated Show resolved Hide resolved
@kirangodishala kirangodishala force-pushed the optimize_executions branch 2 times, most recently from fb4fd18 to 40fd05d Compare November 28, 2024 17:20
@Nonnull pipelineConfigIds: List<String>,
@Nonnull criteria: ExecutionCriteria
): List<String> {
return primary.retrieveAndFilterPipelineExecutionIdsForApplication(application, pipelineConfigIds, criteria) +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR: BUT ... this ordering DOES matter on the selection criteria and don't think we have a test for this (aka primary MUST come first or it'd select previous data potentially). Just an observation that this is missing a test .. but not sure how "critical" that test really is.

var baseQueryPredicate = field("application").eq(application)
.and(field("config_id").`in`(*pipelineConfigIds.toTypedArray()))

var table = if (jooq.dialect() == SQLDialect.MYSQL) PIPELINE.tableName.forceIndex("pipeline_application_idx")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: DO we really want to force an index, or is another index on the combination needed? OR perhaps merging a couple of these indexes. NOT sure best solution but... we have a number of indexes with some of this data and wondering if we couldn't do this a touch cleaner. I'd EXPECT the optimizer to handle MOST of this without the need to force an index.

@christosarvanitis
Copy link
Member

The whole idea seems like a good optimisation to me 👍 @dbyron-sf @kirangodishala how long have you been running this in your forks?

Also could we fit the same concept of optimisations in retrievePipelinesForPipelineConfigIdsBetweenBuildTimeBoundary in this PR?

kirangodishala and others added 7 commits December 13, 2024 22:12
…perties

optimize getPipelinesForApplication() by reducing the number of relevant pipeline config ids to query

This is a breaking change:
TaskController previously looked at these properties:
`tasks.days-of-execution-history`
`tasks.number-of-old-pipeline-executions-to-include`
and now they live in `tasks.controller`.

fix(web): give java code access to groovy
to fix below error:

> Task :orca-web:compileJava FAILED
../orca/orca-web/src/main/java/com/netflix/spinnaker/config/TaskControllerConfigurationProperties.java:19: error: cannot find symbol
import com.netflix.spinnaker.orca.controllers.TaskController;
                                             ^
  symbol:   class TaskController
  location: package com.netflix.spinnaker.orca.controllers
1 error
…ion() further by processing multiple pipeline config ids at a time and multi-threading each config id batch
refactor function and variable names to make them more descriptive
Copy link
Member

@jasonmcintosh jasonmcintosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There.. are long term things I'd like to evaluate - primarily DB indexes & see if we can move some of this logic out of code or simplify it in some way, but... this is a good start on improving the response times. I worry a touch in a COUPLE spots on how it handles things around in-memory/threads, but for now, approved.

@dbyron-sf dbyron-sf added the ready to merge Approved and ready for merge label Dec 19, 2024
@mergify mergify bot added the auto merged Merged automatically by a bot label Dec 19, 2024
@mergify mergify bot merged commit d739295 into spinnaker:master Dec 19, 2024
5 checks passed
kirangodishala added a commit to kirangodishala/spinnaker.io that referenced this pull request Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merged Merged automatically by a bot ready to merge Approved and ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants