From 25147c6653390976315d650b4ddca000d0b6de50 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Sat, 1 Feb 2014 20:49:42 -0800 Subject: [PATCH] Remove defer support, required for large execution stacks on Ruby 1.9 --- lib/sidekiq/processor.rb | 58 ++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index 4a0e6297..2a445cea 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -34,32 +34,30 @@ module Sidekiq msgstr = work.message queue = work.queue_name - do_defer do - @boss.async.real_thread(proxy_id, Thread.current) + @boss.async.real_thread(proxy_id, Thread.current) - ack = true - begin - msg = Sidekiq.load_json(msgstr) - klass = msg['class'].constantize - worker = klass.new - worker.jid = msg['jid'] + ack = true + begin + msg = Sidekiq.load_json(msgstr) + klass = msg['class'].constantize + worker = klass.new + worker.jid = msg['jid'] - stats(worker, msg, queue) do - Sidekiq.server_middleware.invoke(worker, msg, queue) do - worker.perform(*cloned(msg['args'])) - end + stats(worker, msg, queue) do + Sidekiq.server_middleware.invoke(worker, msg, queue) do + worker.perform(*cloned(msg['args'])) end - rescue Sidekiq::Shutdown - # Had to force kill this job because it didn't finish - # within the timeout. Don't acknowledge the work since - # we didn't properly finish it. - ack = false - rescue Exception => ex - handle_exception(ex, msg || { :message => msgstr }) - raise - ensure - work.acknowledge if ack end + rescue Sidekiq::Shutdown + # Had to force kill this job because it didn't finish + # within the timeout. Don't acknowledge the work since + # we didn't properly finish it. + ack = false + rescue Exception => ex + handle_exception(ex, msg || { :message => msgstr }) + raise + ensure + work.acknowledge if ack end @boss.async.processor_done(current_actor) @@ -71,22 +69,6 @@ module Sidekiq private - # We use Celluloid's defer to workaround tiny little - # Fiber stacks (4kb!) in MRI 1.9. - # - # For some reason, Celluloid's thread dispatch, TaskThread, - # is unstable under heavy concurrency but TaskFiber has proven - # itself stable. - NEED_DEFER = (RUBY_ENGINE == 'ruby' && RUBY_VERSION < '2.0.0') - - def do_defer(&block) - if NEED_DEFER - defer(&block) - else - yield - end - end - def identity @str ||= "#{hostname}:#{process_id}-#{Thread.current.object_id}:default" end