summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2017-11-21 18:44:52 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2017-11-27 11:56:15 +0100
commita26e25ea757f475afa1b6fd667c58fe15e306022 (patch)
tree8cfe4171f30c7080b9083f2c49e21dab5522f30c
parent03b891c5791f17bbe426a47f53e0f46704543182 (diff)
downloadgitlab-ce-a26e25ea757f475afa1b6fd667c58fe15e306022.tar.gz
Optimise StuckCiJobsWorker
-rw-r--r--app/workers/stuck_ci_jobs_worker.rb11
-rw-r--r--changelogs/unreleased/optimise-stuck-ci-jobs-worker.yml5
2 files changed, 13 insertions, 3 deletions
diff --git a/app/workers/stuck_ci_jobs_worker.rb b/app/workers/stuck_ci_jobs_worker.rb
index fdbc049c2df..566b4507965 100644
--- a/app/workers/stuck_ci_jobs_worker.rb
+++ b/app/workers/stuck_ci_jobs_worker.rb
@@ -45,9 +45,13 @@ class StuckCiJobsWorker
end
def search(status, timeout)
- builds = Ci::Build.where(status: status).where('ci_builds.updated_at < ?', timeout.ago)
- builds.joins(:project).merge(Project.without_deleted).includes(:tags, :runner, project: :namespace).find_each(batch_size: 50).each do |build|
- yield(build)
+ Ci::Build.where(status: status).in_batches(of: 1000) do |batch|
+ batch = batch.where('ci_builds.updated_at < ?', timeout.ago)
+ .joins(:project).merge(Project.without_deleted)
+ .includes(:tags, :runner, project: :namespace)
+ batch.each do |build|
+ yield(build)
+ end
end
end
@@ -58,3 +62,4 @@ class StuckCiJobsWorker
end
end
end
+
diff --git a/changelogs/unreleased/optimise-stuck-ci-jobs-worker.yml b/changelogs/unreleased/optimise-stuck-ci-jobs-worker.yml
new file mode 100644
index 00000000000..7f6adfb4fd8
--- /dev/null
+++ b/changelogs/unreleased/optimise-stuck-ci-jobs-worker.yml
@@ -0,0 +1,5 @@
+---
+title: Optimise StuckCiJobsWorker using cheap SQL query outside, and expensive inside
+merge_request:
+author:
+type: performance