Commit 7907b6b9 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Configure connection pools for ActionCable

Use ActionCable's worker pool size to determine connection pool size
parent 0d07b239
......@@ -3,4 +3,6 @@
require ::File.expand_path('../../config/environment', __FILE__)
Rails.application.eager_load!
ACTION_CABLE_SERVER = true
run ActionCable.server
......@@ -1065,6 +1065,11 @@ production: &base
# host: localhost
# port: 3808
## ActionCable settings
action_cable:
# Number of threads used to process ActionCable connection callbacks and channel actions
# worker_pool_size: 4
## Monitoring
# Built in monitoring settings
monitoring:
......
......@@ -717,6 +717,12 @@ Settings.webpack.dev_server['enabled'] ||= false
Settings.webpack.dev_server['host'] ||= 'localhost'
Settings.webpack.dev_server['port'] ||= 3808
#
# ActionCable settings
#
Settings['action_cable'] ||= Settingslogic.new({})
Settings.action_cable['worker_pool_size'] ||= 4
#
# Monitoring settings
#
......
......@@ -5,4 +5,5 @@ Rails.application.configure do
# we're running ActionCable as a standalone server
config.action_cable.mount_path = nil
config.action_cable.url = Gitlab::Utils.append_path(Gitlab.config.gitlab.relative_url_root, '/-/cable')
config.action_cable.worker_pool_size = Gitlab.config.action_cable.worker_pool_size
end
......@@ -37,7 +37,7 @@ module Gitlab
end
def puma?
!!defined?(::Puma)
!!defined?(::Puma) && !defined?(ACTION_CABLE_SERVER)
end
# For unicorn, we need to check for actual server instances to avoid false positives.
......@@ -70,25 +70,31 @@ module Gitlab
end
def web_server?
puma? || unicorn?
puma? || unicorn? || action_cable?
end
def action_cable?
!!defined?(ACTION_CABLE_SERVER)
end
def multi_threaded?
puma? || sidekiq?
puma? || sidekiq? || action_cable?
end
def max_threads
main_thread = 1
if puma?
Puma.cli_config.options[:max_threads] + main_thread
if action_cable?
Gitlab::Application.config.action_cable.worker_pool_size
elsif puma?
Puma.cli_config.options[:max_threads]
elsif sidekiq?
# An extra thread for the poller in Sidekiq Cron:
# https://github.com/ondrejbartas/sidekiq-cron#under-the-hood
Sidekiq.options[:concurrency] + main_thread + 1
Sidekiq.options[:concurrency] + 1
else
main_thread
end
0
end + main_thread
end
end
end
......
......@@ -105,4 +105,17 @@ describe Gitlab::Runtime do
it_behaves_like "valid runtime", :rails_runner, 1
end
context "action_cable" do
before do
stub_const('ACTION_CABLE_SERVER', true)
stub_const('::Puma', Module.new)
allow(Gitlab::Application).to receive_message_chain(:config, :action_cable, :worker_pool_size).and_return(8)
end
it "reports its maximum concurrency based on ActionCable's worker pool size" do
expect(subject.max_threads).to eq(9)
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