From 692ae11f5814e318964f90db2087bd9d11563b20 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 9 Nov 2009 02:37:26 -0800 Subject: rev_thread_spawn: make 1.9 TeeInput performance tolerable Somehow 1.8 performance blows with shorter reads in the Rack application. This may be because the Rev framework uses a default 16K IO size and our test applications may request less. --- lib/rainbows/rev_thread_spawn.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'lib/rainbows/rev_thread_spawn.rb') diff --git a/lib/rainbows/rev_thread_spawn.rb b/lib/rainbows/rev_thread_spawn.rb index f0482fd..4eba6d9 100644 --- a/lib/rainbows/rev_thread_spawn.rb +++ b/lib/rainbows/rev_thread_spawn.rb @@ -18,23 +18,24 @@ module Rainbows # # Caveats: # - # * TeeInput performance is currently terrible under Ruby 1.9.1-p243 - # with few, fast clients. This appears to be due the Queue - # implementation in 1.9. + # * TeeInput performance is terrible unless you match the + # length argument of your env["rack.input"]#read calls + # so that it is equal to Rev::IO::INPUT_SIZE module RevThreadSpawn class Client < Rainbows::Rev::Client include EvThreadCore LOOP = ::Rev::Loop.default DR = Rainbows::Rev::DeferredResponse + TEE_RESUMER = ::Rev::AsyncWatcher.new def pause - @lock.synchronize { detach } + @lock.synchronize { disable if enabled? } end def resume - # we always attach to the loop belonging to the main thread - @lock.synchronize { attach(LOOP) } + @lock.synchronize { enable unless enabled? } + TEE_RESUMER.signal end def write(data) @@ -74,5 +75,11 @@ module Rainbows end include Rainbows::Rev::Core + + def init_worker_process(worker) + super + Client::TEE_RESUMER.attach(::Rev::Loop.default) + end + end end -- cgit v1.2.3-24-ge0c7