diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-12-30 08:33:15 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-04 16:37:42 -0800 |
commit | e21939d776673b2f8887adf7a5c64812b7d2e98e (patch) | |
tree | 48aa3a71201e770758bd09b325c3f2704411af7f /lib/rainbows/writer_thread_pool.rb | |
parent | 4a76da1833922c74e147be5def9bfe04fd0c16a2 (diff) | |
download | rainbows-e21939d776673b2f8887adf7a5c64812b7d2e98e.tar.gz |
Rack::Utils::HeaderHash is still very expensive in Rack 1.2, especially for simple things that we want to run as fast as possible with minimal interference. HeaderHash is unnecessary for most requests that do not send Content-Range in responses.
Diffstat (limited to 'lib/rainbows/writer_thread_pool.rb')
-rw-r--r-- | lib/rainbows/writer_thread_pool.rb | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/lib/rainbows/writer_thread_pool.rb b/lib/rainbows/writer_thread_pool.rb index 67c8e83..558827f 100644 --- a/lib/rainbows/writer_thread_pool.rb +++ b/lib/rainbows/writer_thread_pool.rb @@ -19,30 +19,14 @@ module Rainbows::WriterThreadPool # :stopdoc: include Rainbows::Base + autoload :Client, 'rainbows/writer_thread_pool/client' @@nr = 0 @@q = nil - def async_write_body(qclient, body, range) - if body.respond_to?(:close) - Rainbows::SyncClose.new(body) do |body| - qclient.q << [ qclient.to_io, :body, body, range ] - end - else - qclient.q << [ qclient.to_io, :body, body, range ] - end - end - def process_client(client) # :nodoc: @@nr += 1 - super(Client.new(client, @@q[@@nr %= @@q.size])) - end - - def init_worker_process(worker) - super - self.class.__send__(:alias_method, :sync_write_body, :write_body) - Rainbows::WriterThreadPool.__send__( - :alias_method, :write_body, :async_write_body) + Client.new(client, @@q[@@nr %= @@q.size]).process_loop end def worker_loop(worker) # :nodoc: @@ -51,12 +35,16 @@ module Rainbows::WriterThreadPool qp = (1..worker_connections).map do |n| Rainbows::QueuePool.new(1) do |response| begin - io, arg1, arg2, arg3 = response - case arg1 - when :body then sync_write_body(io, arg2, arg3) - when :close then io.close unless io.closed? + io, arg, *rest = response + case arg + when String + io.kgio_write(arg) + when :close + warn "#{Thread.current} #{io} close" + io.close unless io.closed? else - io.write(arg1) + warn "#{Thread.current} #{io} #{arg}" + io.__send__(arg, *rest) end rescue => err Rainbows::Error.write(io, err) @@ -70,5 +58,3 @@ module Rainbows::WriterThreadPool end # :startdoc: end -# :enddoc: -require 'rainbows/writer_thread_pool/client' |