Skip to content
Snippets Groups Projects
Unverified Commit 931ff815 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Re-organize queues to use for Sidekiq

Dumping too many jobs in the same queue (e.g. the "default" queue) is a
dangerous setup. Jobs that take a long time to process can effectively
block any other work from being performed given there are enough of
these jobs.

Furthermore it becomes harder to monitor the jobs as a single queue
could contain jobs for different workers. In such a setup the only
reliable way of getting counts per job is to iterate over all jobs in a
queue, which is a rather time consuming process.

By using separate queues for various workers we have better control over
throughput, we can add weight to queues, and we can monitor queues
better. Some workers still use the same queue whenever their work is
related. For example, the various CI pipeline workers use the same
"pipeline" queue.

This commit includes a Rails migration that moves Sidekiq jobs from the
old queues to the new ones. This migration also takes care of doing the
inverse if ever needed. This does require downtime as otherwise new jobs
could be scheduled in the old queues after this migration completes.

This commit also includes an RSpec test that blacklists the use of the
"default" queue and ensures cron workers use the "cronjob" queue.

Fixes gitlab-org/gitlab-ce#23370
parent c41ed4d1
No related branches found
No related tags found
No related merge requests found
Showing
with 60 additions and 11 deletions
Loading
Loading
@@ -2,6 +2,9 @@ Please view this file on the master branch, on stable branches it's out of date.
 
## 8.13.0 (2016-10-22)
 
- Fix save button on project pipeline settings page. (!6955)
- All Sidekiq workers now use their own queue
- Avoid race condition when asynchronously removing expired artifacts. (!6881)
- Improve Merge When Build Succeeds triggers and execute on pipeline success. (!6675)
- Respond with 404 Not Found for non-existent tags (Linus Thiel)
- Truncate long labels with ellipsis in labels page
Loading
Loading
class AdminEmailWorker
include Sidekiq::Worker
sidekiq_options retry: false # this job auto-repeats via sidekiq-cron
include CronjobQueue
 
def perform
repository_check_failed_count = Project.where(last_repository_check_failed: true).count
Loading
Loading
class BuildCoverageWorker
include Sidekiq::Worker
sidekiq_options queue: :default
include BuildQueue
 
def perform(build_id)
Ci::Build.find_by(id: build_id)
Loading
Loading
class BuildEmailWorker
include Sidekiq::Worker
include BuildQueue
 
def perform(build_id, recipients, push_data)
recipients.each do |recipient|
Loading
Loading
class BuildFinishedWorker
include Sidekiq::Worker
include BuildQueue
 
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
Loading
Loading
class BuildHooksWorker
include Sidekiq::Worker
sidekiq_options queue: :default
include BuildQueue
 
def perform(build_id)
Ci::Build.find_by(id: build_id)
Loading
Loading
class BuildSuccessWorker
include Sidekiq::Worker
sidekiq_options queue: :default
include BuildQueue
 
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
Loading
Loading
# This worker clears all cache fields in the database, working in batches.
class ClearDatabaseCacheWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
 
BATCH_SIZE = 1000
 
Loading
Loading
# Concern for setting Sidekiq settings for the various CI build workers.
module BuildQueue
extend ActiveSupport::Concern
included do
sidekiq_options queue: :build
end
end
# Concern that sets various Sidekiq settings for workers executed using a
# cronjob.
module CronjobQueue
extend ActiveSupport::Concern
included do
sidekiq_options queue: :cronjob, retry: false
end
end
# Concern that sets the queue of a Sidekiq worker based on the worker's class
# name/namespace.
module DedicatedSidekiqQueue
extend ActiveSupport::Concern
included do
sidekiq_options queue: name.sub(/Worker\z/, '').underscore.tr('/', '_')
end
end
# Concern for setting Sidekiq settings for the various CI pipeline workers.
module PipelineQueue
extend ActiveSupport::Concern
included do
sidekiq_options queue: :pipeline
end
end
# Concern for setting Sidekiq settings for the various repository check workers.
module RepositoryCheckQueue
extend ActiveSupport::Concern
included do
sidekiq_options queue: :repository_check, retry: false
end
end
class DeleteUserWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
 
def perform(current_user_id, delete_user_id, options = {})
delete_user = User.find(delete_user_id)
Loading
Loading
class EmailReceiverWorker
include Sidekiq::Worker
sidekiq_options queue: :incoming_email
include DedicatedSidekiqQueue
 
def perform(raw)
return unless Gitlab::IncomingEmail.enabled?
Loading
Loading
class EmailsOnPushWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
 
sidekiq_options queue: :mailers
attr_reader :email, :skip_premailer
 
def perform(project_id, recipients, push_data, options = {})
Loading
Loading
class ExpireBuildArtifactsWorker
include Sidekiq::Worker
include CronjobQueue
 
def perform
Rails.logger.info 'Scheduling removal of build artifacts'
Loading
Loading
class ExpireBuildInstanceArtifactsWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
 
def perform(build_id)
build = Ci::Build.with_expired_artifacts.reorder(nil).find_by(id: build_id)
Loading
Loading
class GitGarbageCollectWorker
include Sidekiq::Worker
include Gitlab::ShellAdapter
include DedicatedSidekiqQueue
 
sidekiq_options queue: :gitlab_shell, retry: false
sidekiq_options retry: false
 
def perform(project_id)
project = Project.find(project_id)
Loading
Loading
class GitlabShellWorker
include Sidekiq::Worker
include Gitlab::ShellAdapter
sidekiq_options queue: :gitlab_shell
include DedicatedSidekiqQueue
 
def perform(action, *arg)
gitlab_shell.send(action, *arg)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment