From 41e4396a5549399eb808d74086cb6f4b9471b882 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 5 Feb 2015 20:43:51 +0530 Subject: [PATCH] Configurable worker pool size --- lib/action_cable/channel/base.rb | 2 +- lib/action_cable/server.rb | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index af328cf297..a3aa4df2ad 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -67,7 +67,7 @@ module ActionCable def start_periodic_timers self.class.periodic_timers.each do |callback, options| @_active_periodic_timers << EventMachine::PeriodicTimer.new(options[:every]) do - Celluloid::Actor[:worker_pool].async.run_periodic_timer(self, callback) + connection.class.worker_pool.async.run_periodic_timer(self, callback) end end end diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb index 10c94734ef..d1b7e14b53 100644 --- a/lib/action_cable/server.rb +++ b/lib/action_cable/server.rb @@ -1,10 +1,11 @@ -Celluloid::Actor[:worker_pool] = ActionCable::Worker.pool(size: 100) - module ActionCable class Server class_attribute :registered_channels self.registered_channels = Set.new + class_attribute :worker_pool_size + self.worker_pool_size = 100 + class << self def register_channels(*channel_classes) self.registered_channels += channel_classes @@ -13,6 +14,10 @@ module ActionCable def call(env) new(env).process end + + def worker_pool + @worker_pool ||= ActionCable::Worker.pool(size: worker_pool_size) + end end def initialize(env) @@ -27,11 +32,11 @@ module ActionCable @websocket.on(:message) do |event| message = event.data - Celluloid::Actor[:worker_pool].async.received_data(self, message) if message.is_a?(String) + self.class.worker_pool.async.received_data(self, message) if message.is_a?(String) end @websocket.on(:close) do |event| - Celluloid::Actor[:worker_pool].async.cleanup_subscriptions(self) + self.class.worker_pool.async.cleanup_subscriptions(self) end @websocket.rack_response