rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 94203f349a79b02d33b2b74b38be8fd954b896c5 1201 bytes (raw)
$ git show v0.91.0:lib/rainbows/rev_thread_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
30
31
32
33
34
35
36
37
38
 
# -*- encoding: binary -*-
require 'rainbows/rev/thread'

module Rainbows

  # A combination of the Rev and ThreadSpawn models.  This allows Ruby
  # Thread-based concurrency for application processing.  It DOES NOT
  # expose a streamable "rack.input" for upload processing within the
  # app.  DevFdResponse should be used with this class to proxy
  # asynchronous responses.  All network I/O between the client and
  # server are handled by the main thread and outside of the core
  # application dispatch.
  #
  # Unlike ThreadSpawn, Rev makes this model highly suitable for
  # slow clients and applications with medium-to-slow response times
  # (I/O bound), but less suitable for sleepy applications.
  #
  # Ruby 1.8 users are strongly advised to use Rev >= 0.3.2 to get
  # usable performance.

  module RevThreadSpawn

    class Client < Rainbows::Rev::ThreadClient
      def app_dispatch
        Thread.new(self) { |client| MASTER << [ client, app_response ] }
      end
    end

    include Rainbows::Rev::Core

    def init_worker_process(worker)
      super
      master = Rev::Master.new(Queue.new).attach(::Rev::Loop.default)
      Client.const_set(:MASTER, master)
    end

  end
end

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