add client_header_buffer_size tuning parameter
[rainbows.git] / lib / rainbows / configurator.rb
blobb596b0b4a5df38fc404e4527a3390b9c392c4d83
1 # -*- encoding: binary -*-
3 # This module adds \Rainbows! to the
4 # {Unicorn::Configurator}[http://unicorn.bogomips.org/Unicorn/Configurator.html]
5 module Rainbows::Configurator
7   # configures \Rainbows! with a given concurrency model to +use+ and
8   # a +worker_connections+ upper-bound.  This method may be called
9   # inside a Unicorn/\Rainbows! configuration file:
10   #
11   #   Rainbows! do
12   #     use :ThreadSpawn # concurrency model to use
13   #     worker_connections 400
14   #     keepalive_timeout 0 # zero disables keepalives entirely
15   #     client_max_body_size 5*1024*1024 # 5 megabytes
16   #     keepalive_requests 666 # default:100
17   #     client_header_buffer_size 16 * 1024 # 16 kilobytes
18   #   end
19   #
20   #   # the rest of the Unicorn configuration
21   #   worker_processes 8
22   #
23   # See the documentation for the respective Revactor, ThreadSpawn,
24   # and ThreadPool classes for descriptions and recommendations for
25   # each of them.  The total number of clients we're able to serve is
26   # +worker_processes+ * +worker_connections+, so in the above example
27   # we can serve 8 * 400 = 3200 clients concurrently.
28   #
29   # The default is +keepalive_timeout+ is 5 seconds, which should be
30   # enough under most conditions for browsers to render the page and
31   # start retrieving extra elements for.  Increasing this beyond 5
32   # seconds is not recommended.  Zero disables keepalive entirely
33   # (but pipelining fully-formed requests is still works).
34   #
35   # The default +client_max_body_size+ is 1 megabyte (1024 * 1024 bytes),
36   # setting this to +nil+ will disable body size checks and allow any
37   # size to be specified.
38   #
39   # The default +keepalive_requests+ is 100, meaning a client may
40   # complete 100 keepalive requests after the initial request before
41   # \Rainbows! forces a disconnect.  Lowering this can improve
42   # load-balancing characteristics as it forces HTTP/1.1 clients to
43   # reconnect after the specified number of requests, hopefully to a
44   # less busy host or worker process.  This may also be used to mitigate
45   # denial-of-service attacks that use HTTP pipelining.
46   def Rainbows!(&block)
47     block_given? or raise ArgumentError, "Rainbows! requires a block"
48     Rainbows::HttpServer.setup(block)
49   end
50 end
52 # :enddoc:
53 # inject the Rainbows! method into Unicorn::Configurator
54 Unicorn::Configurator.__send__(:include, Rainbows::Configurator)