1 # -*- encoding: binary -*-
6 require 'rainbows/const'
7 require 'rainbows/http_server'
8 require 'rainbows/http_response'
9 require 'rainbows/base'
13 # runs the Rainbows! HttpServer with +app+ and +options+ and does
14 # not return until the server has exited.
15 def run(app, options = {})
16 HttpServer.new(app, options).start.join
20 # configures \Rainbows! with a given concurrency model to +use+ and
21 # a +worker_connections+ upper-bound. This method may be called
22 # inside a Unicorn/Rainbows configuration file:
25 # use :Revactor # this may also be :ThreadSpawn or :ThreadPool
26 # worker_connections 400
29 # # the rest of the Unicorn configuration
32 # See the documentation for the respective Revactor, ThreadSpawn,
33 # and ThreadPool classes for descriptions and recommendations for
34 # each of them. The total number of clients we're able to serve is
35 # +worker_processes+ * +worker_connections+, so in the above example
36 # we can serve 8 * 400 = 3200 clients concurrently.
38 block_given? or raise ArgumentError, "Rainbows! requires a block"
39 HttpServer.setup(block)
42 # maps models to default worker counts, default worker count numbers are
43 # pretty arbitrary and tuning them to your application and hardware is
45 MODEL_WORKER_CONNECTIONS = {
46 :Base => 1, # this one can't change
51 u = model.to_s.gsub(/([a-z0-9])([A-Z0-9])/) { "#{$1}_#{$2.downcase!}" }
52 autoload model, "rainbows/#{u.downcase!}"
57 # inject the Rainbows! method into Unicorn::Configurator
58 Unicorn::Configurator.class_eval { include Rainbows }