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:
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
19 # # the rest of the Unicorn configuration
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.
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).
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.
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.
46 block_given? or raise ArgumentError, "Rainbows! requires a block"
47 Rainbows::HttpServer.setup(block)
52 # inject the Rainbows! method into Unicorn::Configurator
53 Unicorn::Configurator.__send__(:include, Rainbows::Configurator)