Apply optimizations to JobsController#show.json [RUN ALL RSPEC] [RUN AS-IF-FOSS]
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) |
---|---|
![]() |
![]() |
We get a ~2x response speed improvement.
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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