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'
17 autoload :DevFdResponse, 'rainbows/dev_fd_response'
21 # runs the Rainbows! HttpServer with +app+ and +options+ and does
22 # not return until the server has exited.
23 def run(app, options = {})
24 HttpServer.new(app, options).start.join
28 # configures \Rainbows! with a given concurrency model to +use+ and
29 # a +worker_connections+ upper-bound. This method may be called
30 # inside a Unicorn/Rainbows configuration file:
33 # use :Revactor # this may also be :ThreadSpawn or :ThreadPool
34 # worker_connections 400
37 # # the rest of the Unicorn configuration
40 # See the documentation for the respective Revactor, ThreadSpawn,
41 # and ThreadPool classes for descriptions and recommendations for
42 # each of them. The total number of clients we're able to serve is
43 # +worker_processes+ * +worker_connections+, so in the above example
44 # we can serve 8 * 400 = 3200 clients concurrently.
46 block_given? or raise ArgumentError, "Rainbows! requires a block"
47 HttpServer.setup(block)
50 # maps models to default worker counts, default worker count numbers are
51 # pretty arbitrary and tuning them to your application and hardware is
53 MODEL_WORKER_CONNECTIONS = {
54 :Base => 1, # this one can't change
61 u = model.to_s.gsub(/([a-z0-9])([A-Z0-9])/) { "#{$1}_#{$2.downcase!}" }
62 autoload model, "rainbows/#{u.downcase!}"
67 # inject the Rainbows! method into Unicorn::Configurator
68 Unicorn::Configurator.class_eval { include Rainbows }