Commit e840749b authored by Patricio Cano's avatar Patricio Cano

Refactored Sidekiq Throttler and updated documentation

parent 20853049
...@@ -19,7 +19,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -19,7 +19,7 @@ class ApplicationSetting < ActiveRecord::Base
serialize :domain_whitelist, Array serialize :domain_whitelist, Array
serialize :domain_blacklist, Array serialize :domain_blacklist, Array
serialize :repository_storages serialize :repository_storages
serialize :sidekiq_throttling_queues serialize :sidekiq_throttling_queues, Array
cache_markdown_field :sign_in_text cache_markdown_field :sign_in_text
cache_markdown_field :help_page_text cache_markdown_field :help_page_text
......
...@@ -304,9 +304,9 @@ ...@@ -304,9 +304,9 @@
.form-group .form-group
= f.label :sidekiq_throttling_factor, 'Throttling Factor', class: 'control-label col-sm-2' = f.label :sidekiq_throttling_factor, 'Throttling Factor', class: 'control-label col-sm-2'
.col-sm-10 .col-sm-10
= f.number_field :sidekiq_throttling_factor, class: 'form-control', min: '0', max: '0.99', step: '0.01' = f.number_field :sidekiq_throttling_factor, class: 'form-control', min: '0.01', max: '0.99', step: '0.01'
.help-block .help-block
The factor by which the queues should be throttled. A value between 0.1 and 0.9. The factor by which the queues should be throttled. A value between 0.0 and 1.0, exclusive.
%fieldset %fieldset
%legend Spam and Anti-bot Protection %legend Spam and Anti-bot Protection
......
--- ---
title: Added ability to throttle Sidekiq Jobs title: Added ability to throttle Sidekiq Jobs
merge_request: 7292 merge_request: 7292
author: Patricio Cano author:
...@@ -3,14 +3,15 @@ ...@@ -3,14 +3,15 @@
> Note: Introduced with GitLab 8.14 > Note: Introduced with GitLab 8.14
When your GitLab installation needs to handle tens of thousands of background When your GitLab installation needs to handle tens of thousands of background
jobs, it can be convenient to prioritize queues that need to be executed jobs, it can be convenient to throttle queues that do not need to be executed
immediately, e.g. user initiated actions like merging a Merge Request. immediately, e.g. long running jobs like Pipelines, thus allowing jobs that do
need to be executed immediately to have access to more resources.
In order to accomplish this, you can limit the amount of workers that certain In order to accomplish this, you can limit the amount of workers that certain
slow running queues get can have available. This is what we call Sidekiq Job slow running queues can have available. This is what we call Sidekiq Job
Throttling. Depending on your infrastructure, you might have different slow Throttling. Depending on your infrastructure, you might have different slow
running queues, which is why you can choose which queues to throttle and by running queues, which is why you can choose which queues you want to throttle
how much you want to throttle them. and by how much you want to throttle them.
These settings are available in the Application Settings of your GitLab These settings are available in the Application Settings of your GitLab
installation. installation.
...@@ -24,8 +25,8 @@ and rounded up to the closest full integer. ...@@ -24,8 +25,8 @@ and rounded up to the closest full integer.
So, for example, you set the `:concurrency` to 25 and the `Throttling factor` to So, for example, you set the `:concurrency` to 25 and the `Throttling factor` to
0.1, the maximum workers assigned to the selected queues would be 3. 0.1, the maximum workers assigned to the selected queues would be 3.
``` ```ruby
limit = (factor * Sidekiq.options[:concurrency]).ceil queue_limit = (factor * Sidekiq.options[:concurrency]).ceil
``` ```
After enabling the job throttling, you will need to restart your GitLab After enabling the job throttling, you will need to restart your GitLab
......
...@@ -3,18 +3,20 @@ module Gitlab ...@@ -3,18 +3,20 @@ module Gitlab
class << self class << self
def execute! def execute!
if Gitlab::CurrentSettings.sidekiq_throttling_enabled? if Gitlab::CurrentSettings.sidekiq_throttling_enabled?
current_application_settings.sidekiq_throttling_queues.each do |queue| Gitlab::CurrentSettings.current_application_settings.sidekiq_throttling_queues.each do |queue|
Sidekiq::Queue[queue].limit = set_limit Sidekiq::Queue[queue].limit = queue_limit
end end
end end
end end
private private
def set_limit def queue_limit
factor = current_application_settings.sidekiq_throttling_factor @queue_limit ||=
begin
(factor * Sidekiq.options[:concurrency]).ceil factor = Gitlab::CurrentSettings.current_application_settings.sidekiq_throttling_factor
(factor * Sidekiq.options[:concurrency]).ceil
end
end end
end end
end end
......
...@@ -11,12 +11,6 @@ describe Gitlab::SidekiqThrottler do ...@@ -11,12 +11,6 @@ describe Gitlab::SidekiqThrottler do
) )
end end
describe '#set_limit' do
it 'returns the correct limit' do
expect(Gitlab::SidekiqThrottler.send(:set_limit)).to eq 4
end
end
describe '#execute!' do describe '#execute!' do
it 'sets limits on the selected queues' do it 'sets limits on the selected queues' do
Gitlab::SidekiqThrottler.execute! Gitlab::SidekiqThrottler.execute!
......
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