Skip to content

Apply optimizations to JobsController#show.json [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Vasilii Iakliushin requested to merge 325333_optimize_query into master

What does this MR do?

Contributes to #325333 (closed)

Feature flag: #326989 (closed)

This MR applies two optimizations

Add cache for runners availability requests

We return the stuck status of the build in BuildDetailsEntity. For that we fetch all available runners for the project and try to find that of them is ready (should be available, online and support tags of the build). For projects with hundreds of runners, we observe the increased response time. In the worst-case situation, we have to go through the whole collection of runners.

I introduced a cache for #any_runners_available? and #any_runners_online? methods. The expiration time is short (1 minute). We mostly display this information on UI so the short lag in refreshing this data should not be noticeable. However, it should save the database from extra queries and improve the response time.

Request online runners

Currently, we fetch active_runner_with_tags and check if they are online? one by one. But if we apply the online scope to the original query then we can reduce the number of unnecessary runners fetched.

Screenshots (strongly suggested)

My local setup (reproducing the worst-case scenario)

Ci::Runners.count
=> 506

Ci::Runner.online.count
=> 0
Before (avg. time 1.54s) After (avg. time 0.73s)
Screenshot_2021-03-24_at_14.25.45 Screenshot_2021-03-24_at_14.26.34

We get a ~2x response speed improvement.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Vasilii Iakliushin

Merge request reports