globally refactor Range handling for responses
[rainbows.git] / lib / rainbows / writer_thread_spawn.rb
blob2f264d92e6e200e76683afde0adf11112b2bb00d
1 # -*- encoding: binary -*-
2 require 'thread'
3 # This concurrency model implements a single-threaded app dispatch and
4 # spawns a new thread for writing responses.  This concurrency model
5 # should be ideal for apps that serve large responses or stream
6 # responses slowly.
8 # Unlike most \Rainbows! concurrency models, WriterThreadSpawn is
9 # designed to run behind nginx just like Unicorn is.  This concurrency
10 # model may be useful for existing Unicorn users looking for more
11 # output concurrency than socket buffers can provide while still
12 # maintaining a single-threaded application dispatch (though if the
13 # response body is generated on-the-fly, it must be thread safe).
15 # For serving large or streaming responses, setting
16 # "proxy_buffering off" in nginx is recommended.  If your application
17 # does not handle uploads, then using any HTTP-aware proxy like
18 # haproxy is fine.  Using a non-HTTP-aware proxy will leave you
19 # vulnerable to slow client denial-of-service attacks.
21 module Rainbows::WriterThreadSpawn
22   include Rainbows::Base
23   autoload :Client, 'rainbows/writer_thread_spawn/client'
25   def process_client(client) # :nodoc:
26     Client.new(client).process_loop
27   end
29   def worker_loop(worker)  # :nodoc:
30     Client.const_set(:MAX, worker_connections)
31     super # accept loop from Unicorn
32     Client.quit
33   end
34   # :startdoc:
35 end
36 # :enddoc: