fix various warnings with "check-warnings" target
[rainbows.git] / lib / rainbows / configurator.rb
blob3203c5ac137e03d639a5cbbf027f930a22612556
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   #   end
18   #
19   #   # the rest of the Unicorn configuration
20   #   worker_processes 8
21   #
22   # See the documentation for the respective Revactor, ThreadSpawn,
23   # and ThreadPool classes for descriptions and recommendations for
24   # each of them.  The total number of clients we're able to serve is
25   # +worker_processes+ * +worker_connections+, so in the above example
26   # we can serve 8 * 400 = 3200 clients concurrently.
27   #
28   # The default is +keepalive_timeout+ is 5 seconds, which should be
29   # enough under most conditions for browsers to render the page and
30   # start retrieving extra elements for.  Increasing this beyond 5
31   # seconds is not recommended.  Zero disables keepalive entirely
32   # (but pipelining fully-formed requests is still works).
33   #
34   # The default +client_max_body_size+ is 1 megabyte (1024 * 1024 bytes),
35   # setting this to +nil+ will disable body size checks and allow any
36   # size to be specified.
37   #
38   # The default +keepalive_requests+ is 100, meaning a client may
39   # complete 100 keepalive requests after the initial request before
40   # \Rainbows! forces a disconnect.  Lowering this can improve
41   # load-balancing characteristics as it forces HTTP/1.1 clients to
42   # reconnect after the specified number of requests, hopefully to a
43   # less busy host or worker process.  This may also be used to mitigate
44   # denial-of-service attacks that use HTTP pipelining.
45   def Rainbows!(&block)
46     block_given? or raise ArgumentError, "Rainbows! requires a block"
47     Rainbows::HttpServer.setup(block)
48   end
49 end
51 # :enddoc:
52 # inject the Rainbows! method into Unicorn::Configurator
53 Unicorn::Configurator.__send__(:include, Rainbows::Configurator)