1 # -*- encoding: binary -*-
6 # global vars because class/instance variables are confusing me :<
7 # this struct is only accessed inside workers and thus private to each
8 G = Struct.new(:cur, :max, :logger, :alive, :app).new
9 # G.cur may not be used the network concurrency model
12 require 'rainbows/const'
13 require 'rainbows/http_server'
14 require 'rainbows/http_response'
15 require 'rainbows/base'
16 autoload :AppPool, 'rainbows/app_pool'
20 # runs the Rainbows! HttpServer with +app+ and +options+ and does
21 # not return until the server has exited.
22 def run(app, options = {})
23 HttpServer.new(app, options).start.join
27 # configures \Rainbows! with a given concurrency model to +use+ and
28 # a +worker_connections+ upper-bound. This method may be called
29 # inside a Unicorn/Rainbows configuration file:
32 # use :Revactor # this may also be :ThreadSpawn or :ThreadPool
33 # worker_connections 400
36 # # the rest of the Unicorn configuration
39 # See the documentation for the respective Revactor, ThreadSpawn,
40 # and ThreadPool classes for descriptions and recommendations for
41 # each of them. The total number of clients we're able to serve is
42 # +worker_processes+ * +worker_connections+, so in the above example
43 # we can serve 8 * 400 = 3200 clients concurrently.
45 block_given? or raise ArgumentError, "Rainbows! requires a block"
46 HttpServer.setup(block)
49 # maps models to default worker counts, default worker count numbers are
50 # pretty arbitrary and tuning them to your application and hardware is
52 MODEL_WORKER_CONNECTIONS = {
53 :Base => 1, # this one can't change
59 u = model.to_s.gsub(/([a-z0-9])([A-Z0-9])/) { "#{$1}_#{$2.downcase!}" }
60 autoload model, "rainbows/#{u.downcase!}"
65 # inject the Rainbows! method into Unicorn::Configurator
66 Unicorn::Configurator.class_eval { include Rainbows }