Skip to content
Browse files

Use Celluloid's exclusive mode to avoid tiny Fiber stack

  • Loading branch information...
1 parent 0fe0a40 commit 3d869cd5b30db878fd16ee954123b988e063cf14 @mperham committed Jun 29, 2012
Showing with 9 additions and 12 deletions.
  1. +1 −0 Gemfile
  2. +8 −12 lib/sidekiq/processor.rb
View
1 Gemfile
@@ -1,6 +1,7 @@
source 'http://rubygems.org'
gemspec
+gem 'celluloid', :github => 'celluloid/celluloid'
gem 'slim'
gem 'sprockets'
gem 'sass'
View
20 lib/sidekiq/processor.rb
@@ -16,6 +16,8 @@ class Processor
include Util
include Celluloid
+ exclusive :process
+
def self.default_middleware
Middleware::Chain.new do |m|
m.add Middleware::Server::ExceptionHandler
@@ -31,19 +33,13 @@ def initialize(boss)
end
def process(msgstr, queue)
- # Celluloid actor calls are performed within a Fiber.
- # This would give us a terribly small 4KB stack on MRI
- # so we use Celluloid's defer to run things in a thread pool
- # in order to get a full-sized stack for the Worker.
- defer do
- msg = Sidekiq.load_json(msgstr)
- klass = constantize(msg['class'])
- worker = klass.new
+ msg = Sidekiq.load_json(msgstr)
+ klass = constantize(msg['class'])
+ worker = klass.new
- stats(worker, msg, queue) do
- Sidekiq.server_middleware.invoke(worker, msg, queue) do
- worker.perform(*msg['args'])
- end
+ stats(worker, msg, queue) do
+ Sidekiq.server_middleware.invoke(worker, msg, queue) do
+ worker.perform(*msg['args'])
end
end
@boss.processor_done!(current_actor)

0 comments on commit 3d869cd

Please sign in to comment.
Something went wrong with that request. Please try again.