rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob afaf82a89d126ff5be7086d777b0e0dba7950d1c 1038 bytes (raw)
$ git show v0.90.0:lib/rainbows/rev_fiber_spawn.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
# -*- encoding: binary -*-
require 'rainbows/fiber/rev'

module Rainbows

  # A combination of the Rev and FiberSpawn models.  This allows Ruby
  # 1.9 Fiber-based concurrency for application processing while
  # exposing a synchronous execution model and using scalable network
  # concurrency provided by Rev.  A "rack.input" is exposed as well
  # being Sunshowers-compatible.  Applications are strongly advised to
  # wrap all slow IO objects (sockets, pipes) using the
  # Rainbows::Fiber::IO or a Rev-compatible class whenever possible.
  module RevFiberSpawn

    include Base
    include Fiber::Rev

    def worker_loop(worker)
      init_worker_process(worker)
      Server.const_set(:MAX, @worker_connections)
      Server.const_set(:APP, G.server.app)
      Heartbeat.new(1, true).attach(::Rev::Loop.default)
      kato = Kato.new.attach(::Rev::Loop.default)
      Rainbows::Fiber::IO.const_set(:KATO, kato)
      LISTENERS.map! { |s| Server.new(s).attach(::Rev::Loop.default) }
      ::Rev::Loop.default.run
    end
  end
end

git clone https://yhbt.net/rainbows.git