Allow the Sidekiq queues to throttle and the factor by which to throttle them to be configurable
This commit is contained in:
parent
9e2964c15a
commit
b95216aaba
8 changed files with 41 additions and 13 deletions
|
@ -118,6 +118,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
|
||||||
:container_registry_token_expire_delay,
|
:container_registry_token_expire_delay,
|
||||||
:enabled_git_access_protocol,
|
:enabled_git_access_protocol,
|
||||||
:sidekiq_throttling_enabled,
|
:sidekiq_throttling_enabled,
|
||||||
|
:sidekiq_throttling_factor,
|
||||||
:housekeeping_enabled,
|
:housekeeping_enabled,
|
||||||
:housekeeping_bitmaps_enabled,
|
:housekeeping_bitmaps_enabled,
|
||||||
:housekeeping_incremental_repack_period,
|
:housekeeping_incremental_repack_period,
|
||||||
|
@ -126,7 +127,8 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
|
||||||
repository_storages: [],
|
repository_storages: [],
|
||||||
restricted_visibility_levels: [],
|
restricted_visibility_levels: [],
|
||||||
import_sources: [],
|
import_sources: [],
|
||||||
disabled_oauth_sign_in_sources: []
|
disabled_oauth_sign_in_sources: [],
|
||||||
|
sidekiq_throttling_queues: []
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,4 +100,8 @@ module ApplicationSettingsHelper
|
||||||
|
|
||||||
options_for_select(options, @application_setting.repository_storages)
|
options_for_select(options, @application_setting.repository_storages)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sidekiq_queue_options_for_select
|
||||||
|
options_for_select(Sidekiq::Queue.all.map(&:name), @application_setting.sidekiq_throttling_queues)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +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
|
||||||
|
|
||||||
cache_markdown_field :sign_in_text
|
cache_markdown_field :sign_in_text
|
||||||
cache_markdown_field :help_page_text
|
cache_markdown_field :help_page_text
|
||||||
|
@ -85,6 +86,15 @@ class ApplicationSetting < ActiveRecord::Base
|
||||||
presence: { message: 'Domain blacklist cannot be empty if Blacklist is enabled.' },
|
presence: { message: 'Domain blacklist cannot be empty if Blacklist is enabled.' },
|
||||||
if: :domain_blacklist_enabled?
|
if: :domain_blacklist_enabled?
|
||||||
|
|
||||||
|
validates :sidekiq_throttling_factor,
|
||||||
|
numericality: { greater_than: 0, less_than: 1 },
|
||||||
|
presence: { message: 'Throttling factor cannot be empty if Sidekiq Throttling is enabled.' },
|
||||||
|
if: :sidekiq_throttling_enabled?
|
||||||
|
|
||||||
|
validates :sidekiq_throttling_queues,
|
||||||
|
presence: { message: 'Queues to throttle cannot be empty if Sidekiq Throttling is enabled.' },
|
||||||
|
if: :sidekiq_throttling_enabled?
|
||||||
|
|
||||||
validates :housekeeping_incremental_repack_period,
|
validates :housekeeping_incremental_repack_period,
|
||||||
presence: true,
|
presence: true,
|
||||||
numericality: { only_integer: true, greater_than: 0 }
|
numericality: { only_integer: true, greater_than: 0 }
|
||||||
|
|
|
@ -295,6 +295,18 @@
|
||||||
Enable Sidekiq Job Throttling
|
Enable Sidekiq Job Throttling
|
||||||
.help-block
|
.help-block
|
||||||
Limit the amount of resources slow running jobs are assigned.
|
Limit the amount of resources slow running jobs are assigned.
|
||||||
|
.form-group
|
||||||
|
= f.label :sidekiq_throttling_queues, 'Sidekiq queues to throttle', class: 'control-label col-sm-2'
|
||||||
|
.col-sm-10
|
||||||
|
= f.select :sidekiq_throttling_queues, sidekiq_queue_options_for_select, { include_hidden: false }, multiple: true, class: 'select2 select-wide', data: { field: 'sidekiq_throttling_queues' }
|
||||||
|
.help-block
|
||||||
|
Choose which queues you wish to throttle.
|
||||||
|
.form-group
|
||||||
|
= f.label :sidekiq_throttling_factor, 'Throttling Factor', class: 'control-label col-sm-2'
|
||||||
|
.col-sm-10
|
||||||
|
= f.number_field :sidekiq_throttling_factor, class: 'form-control', min: '0', max: '0.99', step: '0.01'
|
||||||
|
.help-block
|
||||||
|
The factor by which the queues should be throttled. A value between 0.1 and 0.9.
|
||||||
|
|
||||||
%fieldset
|
%fieldset
|
||||||
%legend Spam and Anti-bot Protection
|
%legend Spam and Anti-bot Protection
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
require 'gitlab/current_settings'
|
|
||||||
include Gitlab::CurrentSettings
|
|
||||||
|
|
||||||
# Custom Redis configuration
|
# Custom Redis configuration
|
||||||
redis_config_hash = Gitlab::Redis.params
|
redis_config_hash = Gitlab::Redis.params
|
||||||
redis_config_hash[:namespace] = Gitlab::Redis::SIDEKIQ_NAMESPACE
|
redis_config_hash[:namespace] = Gitlab::Redis::SIDEKIQ_NAMESPACE
|
||||||
|
@ -32,16 +29,11 @@ Sidekiq.configure_server do |config|
|
||||||
end
|
end
|
||||||
Sidekiq::Cron::Job.load_from_hash! cron_jobs
|
Sidekiq::Cron::Job.load_from_hash! cron_jobs
|
||||||
|
|
||||||
# allow it to fail: it may do so when create_from_defaults is executed before migrations are actually done
|
if Gitlab::CurrentSettings.sidekiq_throttling_enabled?
|
||||||
begin
|
factor = current_application_settings.sidekiq_throttling_factor
|
||||||
throttling_enabled = current_application_settings.sidekiq_throttling_enabled
|
|
||||||
rescue
|
|
||||||
throttling_enabled = false
|
|
||||||
end
|
|
||||||
|
|
||||||
if throttling_enabled
|
current_application_settings.sidekiq_throttling_queues.each do |queue|
|
||||||
{ 'project_cache' => 0.1, 'pipeline' => 0.1 }.each do |queue, ratio|
|
Sidekiq::Queue[queue].limit = (factor * Sidekiq.options[:concurrency]).ceil
|
||||||
Sidekiq::Queue[queue].limit = (ratio * Sidekiq.options[:concurrency]).ceil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,5 +25,7 @@ class AddSidekiqThrottlingToApplicationSettings < ActiveRecord::Migration
|
||||||
|
|
||||||
def change
|
def change
|
||||||
add_column :application_settings, :sidekiq_throttling_enabled, :boolean, default: false
|
add_column :application_settings, :sidekiq_throttling_enabled, :boolean, default: false
|
||||||
|
add_column :application_settings, :sidekiq_throttling_queues, :string
|
||||||
|
add_column :application_settings, :sidekiq_throttling_factor, :decimal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,6 +99,8 @@ ActiveRecord::Schema.define(version: 20161106185620) do
|
||||||
t.text "shared_runners_text_html"
|
t.text "shared_runners_text_html"
|
||||||
t.text "after_sign_up_text_html"
|
t.text "after_sign_up_text_html"
|
||||||
t.boolean "sidekiq_throttling_enabled", default: false
|
t.boolean "sidekiq_throttling_enabled", default: false
|
||||||
|
t.string "sidekiq_throttling_queues"
|
||||||
|
t.decimal "sidekiq_throttling_factor"
|
||||||
t.boolean "housekeeping_enabled", default: true, null: false
|
t.boolean "housekeeping_enabled", default: true, null: false
|
||||||
t.boolean "housekeeping_bitmaps_enabled", default: true, null: false
|
t.boolean "housekeeping_bitmaps_enabled", default: true, null: false
|
||||||
t.integer "housekeeping_incremental_repack_period", default: 10, null: false
|
t.integer "housekeeping_incremental_repack_period", default: 10, null: false
|
||||||
|
|
|
@ -23,6 +23,10 @@ module Gitlab
|
||||||
settings || fake_application_settings
|
settings || fake_application_settings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sidekiq_throttling_enabled?
|
||||||
|
current_application_settings.sidekiq_throttling_enabled
|
||||||
|
end
|
||||||
|
|
||||||
def fake_application_settings
|
def fake_application_settings
|
||||||
OpenStruct.new(
|
OpenStruct.new(
|
||||||
default_projects_limit: Settings.gitlab['default_projects_limit'],
|
default_projects_limit: Settings.gitlab['default_projects_limit'],
|
||||||
|
|
Loading…
Reference in a new issue