Commit 500aa483 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'preload-runner-tags' into 'master'

Preload runner tags for `UpdateBuildQueueService` [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!55543
parents 1a0afd17 830756d2
...@@ -267,6 +267,16 @@ module Ci ...@@ -267,6 +267,16 @@ module Ci
token[0...8] if token token[0...8] if token
end end
def tag_list
return super unless Feature.enabled?(:ci_preload_runner_tags, default_enabled: :yaml)
if tags.loaded?
tags.map(&:name)
else
super
end
end
def has_tags? def has_tags?
tag_list.any? tag_list.any?
end end
......
...@@ -10,6 +10,8 @@ module Ci ...@@ -10,6 +10,8 @@ module Ci
def tick_for(build, runners, metrics) def tick_for(build, runners, metrics)
runners = runners.with_recent_runner_queue runners = runners.with_recent_runner_queue
runners = runners.with_tags if Feature.enabled?(:ci_preload_runner_tags, default_enabled: :yaml)
metrics.observe_active_runners(-> { runners.to_a.size }) metrics.observe_active_runners(-> { runners.to_a.size })
runners.each do |runner| runners.each do |runner|
......
---
title: Preload runner tags for `UpdateBuildQueueService`
merge_request: 55543
author:
type: performance
---
name: ci_preload_runner_tags
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55543
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/323243
milestone: '13.10'
type: development
group: group::memory
default_enabled: false
...@@ -115,4 +115,43 @@ RSpec.describe Ci::UpdateBuildQueueService do ...@@ -115,4 +115,43 @@ RSpec.describe Ci::UpdateBuildQueueService do
it_behaves_like 'does not refresh runner' it_behaves_like 'does not refresh runner'
end end
end end
context 'avoids N+1 queries', :request_store do
let!(:build) { create(:ci_build, pipeline: pipeline, tag_list: %w[a b]) }
let!(:project_runner) { create(:ci_runner, :project, :online, projects: [project], tag_list: %w[a b c]) }
context 'when ci_preload_runner_tags and ci_reduce_queries_when_ticking_runner_queue are enabled' do
before do
stub_feature_flags(
ci_reduce_queries_when_ticking_runner_queue: true,
ci_preload_runner_tags: true
)
end
it 'does execute the same amount of queries regardless of number of runners' do
control_count = ActiveRecord::QueryRecorder.new { subject.execute(build) }.count
create_list(:ci_runner, 10, :project, :online, projects: [project], tag_list: %w[b c d])
expect { subject.execute(build) }.not_to exceed_all_query_limit(control_count)
end
end
context 'when ci_preload_runner_tags and ci_reduce_queries_when_ticking_runner_queue are disabled' do
before do
stub_feature_flags(
ci_reduce_queries_when_ticking_runner_queue: false,
ci_preload_runner_tags: false
)
end
it 'does execute more queries for more runners' do
control_count = ActiveRecord::QueryRecorder.new { subject.execute(build) }.count
create_list(:ci_runner, 10, :project, :online, projects: [project], tag_list: %w[b c d])
expect { subject.execute(build) }.to exceed_all_query_limit(control_count)
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment