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