1 # -*- encoding: binary -*-
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
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
23 include Rainbows::Base
25 def write_body(my_sock, body, range) # :nodoc:
26 my_sock.queue_body(body, range)
29 def process_client(client) # :nodoc:
30 super(Client.new(client))
33 def worker_loop(worker) # :nodoc:
34 Client.const_set(:MAX, worker_connections)
35 super # accept loop from Unicorn
41 require 'rainbows/writer_thread_spawn/client'