about summary refs log tree commit homepage
path: root/lib/rainbows/ev_thread_core.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-09 02:37:26 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-09 02:50:04 -0800
commit692ae11f5814e318964f90db2087bd9d11563b20 (patch)
tree18aa7ba6de637422aa49ec0bb6c796efa93eabab /lib/rainbows/ev_thread_core.rb
parent8cd6f4d94503a568501b6e24bb785a8e002720c9 (diff)
downloadrainbows-692ae11f5814e318964f90db2087bd9d11563b20.tar.gz
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.
Diffstat (limited to 'lib/rainbows/ev_thread_core.rb')
-rw-r--r--lib/rainbows/ev_thread_core.rb18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/rainbows/ev_thread_core.rb b/lib/rainbows/ev_thread_core.rb
index 287b726..e132f18 100644
--- a/lib/rainbows/ev_thread_core.rb
+++ b/lib/rainbows/ev_thread_core.rb
@@ -17,19 +17,15 @@ module Rainbows
     # we pass ourselves off as a Socket to Unicorn::TeeInput and this
     # is the only method Unicorn::TeeInput requires from the socket
     def readpartial(length, buf = "")
+      # we must modify the original buffer if there was one
       length == 0 and return buf.replace("")
-      # try bufferred reads first
-      @tbuf && @tbuf.size > 0 and return buf.replace(@tbuf.read(length))
 
-      tmp = @state.pop
-      diff = tmp.size - length
-      if diff > 0
-        @tbuf ||= ::IO::Buffer.new
-        @tbuf.write(tmp[length, tmp.size])
-        tmp = tmp[0, length]
+      # wait on the main loop to feed us
+      while @tbuf.size == 0
+        @tbuf.write(@state.pop)
+        resume
       end
-      resume
-      buf.replace(tmp)
+      buf.replace(@tbuf.read(length))
     end
 
     def app_spawn(input)
@@ -69,7 +65,7 @@ module Rainbows
         if 0 == @hp.content_length
           app_spawn(HttpRequest::NULL_IO) # common case
         else # nil or len > 0
-          @state, @tbuf = Queue.new, nil
+          @state, @tbuf = Queue.new, ::IO::Buffer.new
           app_spawn(nil)
         end
       when Queue