writer_thread_spawn: worker_connections limits thread spawned
[rainbows.git] / lib / rainbows / rev_thread_spawn.rb
blob94203f349a79b02d33b2b74b38be8fd954b896c5
1 # -*- encoding: binary -*-
2 require 'rainbows/rev/thread'
4 module Rainbows
6   # A combination of the Rev and ThreadSpawn models.  This allows Ruby
7   # Thread-based concurrency for application processing.  It DOES NOT
8   # expose a streamable "rack.input" for upload processing within the
9   # app.  DevFdResponse should be used with this class to proxy
10   # asynchronous responses.  All network I/O between the client and
11   # server are handled by the main thread and outside of the core
12   # application dispatch.
13   #
14   # Unlike ThreadSpawn, Rev makes this model highly suitable for
15   # slow clients and applications with medium-to-slow response times
16   # (I/O bound), but less suitable for sleepy applications.
17   #
18   # Ruby 1.8 users are strongly advised to use Rev >= 0.3.2 to get
19   # usable performance.
21   module RevThreadSpawn
23     class Client < Rainbows::Rev::ThreadClient
24       def app_dispatch
25         Thread.new(self) { |client| MASTER << [ client, app_response ] }
26       end
27     end
29     include Rainbows::Rev::Core
31     def init_worker_process(worker)
32       super
33       master = Rev::Master.new(Queue.new).attach(::Rev::Loop.default)
34       Client.const_set(:MASTER, master)
35     end
37   end
38 end