From 40445641f11f01c6a24bf96c8b80eed5fd33a512 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 Dec 2010 17:59:27 -0800 Subject: [PATCH] complete Rev => Coolio renaming We use Cool.io internally everywhere now, but preserve Rev-based models for anybody using them. --- TODO | 4 +-- lib/rainbows.rb | 4 +-- lib/rainbows/{rev.rb => coolio.rb} | 28 ++++++++++----------- lib/rainbows/{rev => coolio}/client.rb | 18 +++++++------- lib/rainbows/coolio/core.rb | 25 +++++++++++++++++++ .../{rev => coolio}/deferred_chunk_response.rb | 5 ++-- lib/rainbows/{rev => coolio}/deferred_response.rb | 4 +-- lib/rainbows/{rev => coolio}/heartbeat.rb | 8 +++--- lib/rainbows/{rev => coolio}/master.rb | 2 +- lib/rainbows/{rev => coolio}/sendfile.rb | 2 +- lib/rainbows/{rev => coolio}/server.rb | 4 +-- lib/rainbows/{rev => coolio}/thread_client.rb | 6 ++--- .../{rev_fiber_spawn.rb => coolio_fiber_spawn.rb} | 20 +++++++-------- lib/rainbows/coolio_support.rb | 1 - .../{rev_thread_pool.rb => coolio_thread_pool.rb} | 26 +++++++++---------- .../client.rb | 2 +- .../watcher.rb | 2 +- lib/rainbows/coolio_thread_spawn.rb | 17 +++++++++---- .../client.rb | 2 +- lib/rainbows/fiber/coolio.rb | 12 +++++++++ lib/rainbows/fiber/{rev => coolio}/heartbeat.rb | 2 +- lib/rainbows/fiber/{rev => coolio}/methods.rb | 8 +++--- lib/rainbows/fiber/{rev => coolio}/server.rb | 2 +- lib/rainbows/fiber/{rev => coolio}/sleeper.rb | 4 +-- lib/rainbows/fiber/rev.rb | 12 --------- lib/rainbows/rev.rb | 29 ++-------------------- lib/rainbows/rev/core.rb | 25 ------------------- lib/rainbows/rev_fiber_spawn.rb | 19 ++------------ .../{coolio_thread_spawn.rb => rev_thread_pool.rb} | 10 +++++--- lib/rainbows/rev_thread_spawn.rb | 13 ++-------- 30 files changed, 135 insertions(+), 181 deletions(-) copy lib/rainbows/{rev.rb => coolio.rb} (63%) rename lib/rainbows/{rev => coolio}/client.rb (89%) create mode 100644 lib/rainbows/coolio/core.rb rename lib/rainbows/{rev => coolio}/deferred_chunk_response.rb (59%) rename lib/rainbows/{rev => coolio}/deferred_response.rb (71%) rename lib/rainbows/{rev => coolio}/heartbeat.rb (71%) rename lib/rainbows/{rev => coolio}/master.rb (88%) rename lib/rainbows/{rev => coolio}/sendfile.rb (92%) rename lib/rainbows/{rev => coolio}/server.rb (74%) rename lib/rainbows/{rev => coolio}/thread_client.rb (83%) copy lib/rainbows/{rev_fiber_spawn.rb => coolio_fiber_spawn.rb} (52%) copy lib/rainbows/{rev_thread_pool.rb => coolio_thread_pool.rb} (65%) rename lib/rainbows/{rev_thread_pool => coolio_thread_pool}/client.rb (63%) rename lib/rainbows/{rev_thread_pool => coolio_thread_pool}/watcher.rb (77%) rename lib/rainbows/{rev_thread_spawn => coolio_thread_spawn}/client.rb (69%) create mode 100644 lib/rainbows/fiber/coolio.rb rename lib/rainbows/fiber/{rev => coolio}/heartbeat.rb (85%) rename lib/rainbows/fiber/{rev => coolio}/methods.rb (82%) rename lib/rainbows/fiber/{rev => coolio}/server.rb (88%) rename lib/rainbows/fiber/{rev => coolio}/sleeper.rb (64%) delete mode 100644 lib/rainbows/fiber/rev.rb delete mode 100644 lib/rainbows/rev/core.rb copy lib/rainbows/{coolio_thread_spawn.rb => rev_thread_pool.rb} (69%) diff --git a/TODO b/TODO index 0ab8ed2..a49e0c5 100644 --- a/TODO +++ b/TODO @@ -24,11 +24,11 @@ care about. (those who do not require streaming input can use {rack-fiber_pool}[http://github.com/mperham/rack-fiber_pool]) -* RevFiberPool +* CoolioFiberPool * ThreadPoolRevFiber{Spawn,Pool}: just because -* Rev + callcc - current Rev model with callcc (should work with MBARI) +* Coolio + callcc - current Coolio model with callcc (should work with MBARI) * Omnibus - haven't looked into it, probably like Revactor with 1.8? diff --git a/lib/rainbows.rb b/lib/rainbows.rb index 951c3e5..a503bf0 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -54,14 +54,14 @@ module Rainbows # Sleeps the current application dispatch. This will pick the # optimal method to sleep depending on the concurrency model chosen # (which may still suck and block the entire process). Using this - # with the basic :Rev or :EventMachine models is not recommended. + # with the basic :Coolio or :EventMachine models is not recommended. # This should be used within your Rack application. def sleep(nr) case G.server.use when :FiberPool, :FiberSpawn Rainbows::Fiber.sleep(nr) when :RevFiberSpawn, :CoolioFiberSpawn - Rainbows::Fiber::Rev::Sleeper.new(nr) + Rainbows::Fiber::Coolio::Sleeper.new(nr) when :Revactor Actor.sleep(nr) else diff --git a/lib/rainbows/rev.rb b/lib/rainbows/coolio.rb similarity index 63% copy from lib/rainbows/rev.rb copy to lib/rainbows/coolio.rb index 16d00aa..a9075cc 100644 --- a/lib/rainbows/rev.rb +++ b/lib/rainbows/coolio.rb @@ -1,9 +1,8 @@ # -*- encoding: binary -*- require 'rainbows/coolio_support' -# Coolio is the new version of this, use that instead. -# + # Implements a basic single-threaded event model with -# {Rev}[http://rev.rubyforge.org/]. It is capable of handling +# {Cool.io}[http://coolio.github.com/]. It is capable of handling # thousands of simultaneous client connections, but with only a # single-threaded app dispatch. It is suited for slow clients and # fast applications (applications that do not have slow network @@ -12,15 +11,14 @@ require 'rainbows/coolio_support' # thread-safe, reentrancy is only required for the DevFdResponse body # generator. # -# Compatibility: Whatever \Rev itself supports, currently Ruby +# Compatibility: Whatever Cool.io itself supports, currently Ruby # 1.8/1.9. # # This model does not implement as streaming "rack.input" which # allows the Rack application to process data as it arrives. This # means "rack.input" will be fully buffered in memory or to a # temporary file before the application is entered. - -module Rainbows::Rev +module Rainbows::Coolio # :stopdoc: # keep-alive timeout scoreboard KATO = {} @@ -33,15 +31,15 @@ module Rainbows::Rev KATO.compare_by_identity end - autoload :Master, 'rainbows/rev/master' - autoload :ThreadClient, 'rainbows/rev/thread_client' - autoload :DeferredChunkResponse, 'rainbows/rev/deferred_chunk_response' + autoload :Master, 'rainbows/coolio/master' + autoload :ThreadClient, 'rainbows/coolio/thread_client' + autoload :DeferredChunkResponse, 'rainbows/coolio/deferred_chunk_response' # :startdoc: end # :enddoc: -require 'rainbows/rev/heartbeat' -require 'rainbows/rev/server' -require 'rainbows/rev/core' -require 'rainbows/rev/deferred_response' -require 'rainbows/rev/client' -Rainbows::Rev.__send__ :include, Rainbows::Rev::Core +require 'rainbows/coolio/heartbeat' +require 'rainbows/coolio/server' +require 'rainbows/coolio/core' +require 'rainbows/coolio/deferred_response' +require 'rainbows/coolio/client' +Rainbows::Coolio.__send__ :include, Rainbows::Coolio::Core diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/coolio/client.rb similarity index 89% rename from lib/rainbows/rev/client.rb rename to lib/rainbows/coolio/client.rb index e0bccf0..7ecea3c 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/coolio/client.rb @@ -1,13 +1,13 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::Rev::Client < Rev::IO +class Rainbows::Coolio::Client < Coolio::IO include Rainbows::EvCore G = Rainbows::G SF = Rainbows::StreamFile - CONN = Rainbows::Rev::CONN - KATO = Rainbows::Rev::KATO - DeferredResponse = Rainbows::Rev::DeferredResponse - DeferredChunkResponse = Rainbows::Rev::DeferredChunkResponse + CONN = Rainbows::Coolio::CONN + KATO = Rainbows::Coolio::KATO + DeferredResponse = Rainbows::Coolio::DeferredResponse + DeferredChunkResponse = Rainbows::Coolio::DeferredChunkResponse def initialize(io) CONN[self] = false @@ -25,7 +25,7 @@ class Rainbows::Rev::Client < Rev::IO close if @deferred.nil? && @_write_buffer.empty? end - # override the Rev::IO#write method try to write directly to the + # override the Coolio::IO#write method try to write directly to the # kernel socket buffers to avoid an extra userspace copy if # possible. def write(buf) @@ -86,13 +86,13 @@ class Rainbows::Rev::Client < Rev::IO # used for streaming sockets and pipes def stream_response(status, headers, io, body) c = stream_response_headers(status, headers) if headers - # we only want to attach to the Rev::Loop belonging to the + # we only want to attach to the Coolio::Loop belonging to the # main thread in Ruby 1.9 io = (c ? DeferredChunkResponse : DeferredResponse).new(io, self, body) defer_body(io.attach(LOOP)) end - def rev_write_response(response, alive) + def coolio_write_response(response, alive) status, headers, body = response headers = @hp.headers? ? HH.new(headers) : nil @@ -125,7 +125,7 @@ class Rainbows::Rev::Client < Rev::IO @env[REMOTE_ADDR] = @_io.kgio_addr response = APP.call(@env.update(RACK_DEFAULTS)) - rev_write_response(response, alive = @hp.next? && G.alive) + coolio_write_response(response, alive = @hp.next? && G.alive) return quit unless alive && :close != @state @state = :headers disable if enabled? diff --git a/lib/rainbows/coolio/core.rb b/lib/rainbows/coolio/core.rb new file mode 100644 index 0000000..48907ab --- /dev/null +++ b/lib/rainbows/coolio/core.rb @@ -0,0 +1,25 @@ +# -*- encoding: binary -*- +# :enddoc: +module Rainbows::Coolio::Core + include Rainbows::Base + + # runs inside each forked worker, this sits around and waits + # for connections and doesn't die until the parent dies (or is + # given a INT, QUIT, or TERM signal) + def worker_loop(worker) + Rainbows::Response.setup(Rainbows::Coolio::Client) + require 'rainbows/coolio/sendfile' + Rainbows::Coolio::Client.__send__(:include, Rainbows::Coolio::Sendfile) + init_worker_process(worker) + mod = Rainbows.const_get(@use) + rloop = Rainbows::Coolio::Server.const_set(:LOOP, Coolio::Loop.default) + Rainbows::Coolio::Client.const_set(:LOOP, rloop) + Rainbows::Coolio::Server.const_set(:MAX, @worker_connections) + Rainbows::Coolio::Server.const_set(:CL, mod.const_get(:Client)) + Rainbows::EvCore.const_set(:APP, G.server.app) + Rainbows::EvCore.setup + Rainbows::Coolio::Heartbeat.new(1, true).attach(rloop) + LISTENERS.map! { |s| Rainbows::Coolio::Server.new(s).attach(rloop) } + rloop.run + end +end diff --git a/lib/rainbows/rev/deferred_chunk_response.rb b/lib/rainbows/coolio/deferred_chunk_response.rb similarity index 59% rename from lib/rainbows/rev/deferred_chunk_response.rb rename to lib/rainbows/coolio/deferred_chunk_response.rb index 35991d1..6ced2e6 100644 --- a/lib/rainbows/rev/deferred_chunk_response.rb +++ b/lib/rainbows/coolio/deferred_chunk_response.rb @@ -1,8 +1,9 @@ # -*- encoding: binary -*- # :enddoc: # -# this is class is specific to Rev for proxying IO-derived objects -class Rainbows::Rev::DeferredChunkResponse < Rainbows::Rev::DeferredResponse +# this is class is specific to Coolio for proxying IO-derived objects +class Rainbows::Coolio::DeferredChunkResponse < + Rainbows::Coolio::DeferredResponse def on_read(data) @client.write("#{data.size.to_s(16)}\r\n") @client.write(data) diff --git a/lib/rainbows/rev/deferred_response.rb b/lib/rainbows/coolio/deferred_response.rb similarity index 71% rename from lib/rainbows/rev/deferred_response.rb rename to lib/rainbows/coolio/deferred_response.rb index 4a92ee4..2f6f965 100644 --- a/lib/rainbows/rev/deferred_response.rb +++ b/lib/rainbows/coolio/deferred_response.rb @@ -1,9 +1,9 @@ # -*- encoding: binary -*- # :enddoc: # -# this is class is specific to Rev for writing large static files +# this is class is specific to Coolio for writing large static files # or proxying IO-derived objects -class Rainbows::Rev::DeferredResponse < Rev::IO +class Rainbows::Coolio::DeferredResponse < Coolio::IO def initialize(io, client, body) super(io) @client, @body = client, body diff --git a/lib/rainbows/rev/heartbeat.rb b/lib/rainbows/coolio/heartbeat.rb similarity index 71% rename from lib/rainbows/rev/heartbeat.rb rename to lib/rainbows/coolio/heartbeat.rb index c4a9bb9..d1f4747 100644 --- a/lib/rainbows/rev/heartbeat.rb +++ b/lib/rainbows/coolio/heartbeat.rb @@ -1,13 +1,13 @@ # -*- encoding: binary -*- # :enddoc: # This class handles the Unicorn fchmod heartbeat mechanism -# in Rev-based concurrency models to prevent the master +# in Coolio-based concurrency models to prevent the master # process from killing us unless we're blocked. This class # will also detect and execute the graceful exit if triggered # by SIGQUIT -class Rainbows::Rev::Heartbeat < Rev::TimerWatcher - KATO = Rainbows::Rev::KATO - CONN = Rainbows::Rev::CONN +class Rainbows::Coolio::Heartbeat < Coolio::TimerWatcher + KATO = Rainbows::Coolio::KATO + CONN = Rainbows::Coolio::CONN G = Rainbows::G def on_timer diff --git a/lib/rainbows/rev/master.rb b/lib/rainbows/coolio/master.rb similarity index 88% rename from lib/rainbows/rev/master.rb rename to lib/rainbows/coolio/master.rb index 19992c2..4877e8e 100644 --- a/lib/rainbows/rev/master.rb +++ b/lib/rainbows/coolio/master.rb @@ -1,7 +1,7 @@ # -*- encoding: binary -*- # :enddoc: require 'thread' -class Rainbows::Rev::Master < Rev::IOWatcher +class Rainbows::Coolio::Master < Coolio::IOWatcher def initialize(queue) @reader, @writer = Kgio::Pipe.new diff --git a/lib/rainbows/rev/sendfile.rb b/lib/rainbows/coolio/sendfile.rb similarity index 92% rename from lib/rainbows/rev/sendfile.rb rename to lib/rainbows/coolio/sendfile.rb index 42368a1..ead51a8 100644 --- a/lib/rainbows/rev/sendfile.rb +++ b/lib/rainbows/coolio/sendfile.rb @@ -1,6 +1,6 @@ # -*- encoding: binary -*- # :enddoc: -module Rainbows::Rev::Sendfile +module Rainbows::Coolio::Sendfile if IO.method_defined?(:sendfile_nonblock) def rev_sendfile(sf) # +sf+ is a Rainbows::StreamFile object sf.offset += (n = @_io.sendfile_nonblock(sf, sf.offset, sf.count)) diff --git a/lib/rainbows/rev/server.rb b/lib/rainbows/coolio/server.rb similarity index 74% rename from lib/rainbows/rev/server.rb rename to lib/rainbows/coolio/server.rb index b75e593..0d8af8c 100644 --- a/lib/rainbows/rev/server.rb +++ b/lib/rainbows/coolio/server.rb @@ -1,7 +1,7 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::Rev::Server < Rev::IO - CONN = Rainbows::Rev::CONN +class Rainbows::Coolio::Server < Coolio::IO + CONN = Rainbows::Coolio::CONN # CL and MAX will be defined in the corresponding worker loop def on_readable diff --git a/lib/rainbows/rev/thread_client.rb b/lib/rainbows/coolio/thread_client.rb similarity index 83% rename from lib/rainbows/rev/thread_client.rb rename to lib/rainbows/coolio/thread_client.rb index d6e6655..cc284bd 100644 --- a/lib/rainbows/rev/thread_client.rb +++ b/lib/rainbows/coolio/thread_client.rb @@ -2,9 +2,9 @@ # :enddoc: RUBY_VERSION =~ %r{\A1\.8} and - warn "Rev and Threads do not mix well under Ruby 1.8" + warn "Coolio and Threads do not mix well under Ruby 1.8" -class Rainbows::Rev::ThreadClient < Rainbows::Rev::Client +class Rainbows::Coolio::ThreadClient < Rainbows::Coolio::Client def app_call KATO.delete(self) disable if enabled? @@ -15,7 +15,7 @@ class Rainbows::Rev::ThreadClient < Rainbows::Rev::Client # this is only called in the master thread def response_write(response) alive = @hp.next? && G.alive - rev_write_response(response, alive) + coolio_write_response(response, alive) return quit unless alive && :close != @state @state = :headers diff --git a/lib/rainbows/rev_fiber_spawn.rb b/lib/rainbows/coolio_fiber_spawn.rb similarity index 52% copy from lib/rainbows/rev_fiber_spawn.rb copy to lib/rainbows/coolio_fiber_spawn.rb index 8d0d625..9c5af5f 100644 --- a/lib/rainbows/rev_fiber_spawn.rb +++ b/lib/rainbows/coolio_fiber_spawn.rb @@ -1,19 +1,17 @@ # -*- encoding: binary -*- -require 'rainbows/fiber/rev' +require 'rainbows/fiber/coolio' -# CoolioFiberSpawn is the new version of this, use that instead. -# -# A combination of the Rev and FiberSpawn models. This allows Ruby +# A combination of the Coolio 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 +# concurrency provided by Cool.io. 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 Rainbows::RevFiberSpawn +# Rainbows::Fiber::IO or a Cool.io-compatible class whenever possible. +module Rainbows::CoolioFiberSpawn include Rainbows::Base - include Rainbows::Fiber::Rev + include Rainbows::Fiber::Coolio def worker_loop(worker) # :nodoc: Rainbows::Response.setup(Server) @@ -21,8 +19,8 @@ module Rainbows::RevFiberSpawn Server.const_set(:MAX, @worker_connections) Rainbows::Fiber::Base.setup(Server, nil) Server.const_set(:APP, G.server.app) - Heartbeat.new(1, true).attach(Rev::Loop.default) - LISTENERS.map! { |s| Server.new(s).attach(Rev::Loop.default) } - Rev::Loop.default.run + Heartbeat.new(1, true).attach(Coolio::Loop.default) + LISTENERS.map! { |s| Server.new(s).attach(Coolio::Loop.default) } + Coolio::Loop.default.run end end diff --git a/lib/rainbows/coolio_support.rb b/lib/rainbows/coolio_support.rb index d345395..0fe613a 100644 --- a/lib/rainbows/coolio_support.rb +++ b/lib/rainbows/coolio_support.rb @@ -3,7 +3,6 @@ begin require "coolio" Coolio::VERSION >= "1.0.0" or abort "cool.io >= 1.0.0 is required" - Rev = Coolio rescue LoadError require "rev" Rev::VERSION >= "0.3.0" or abort "rev >= 0.3.0 is required" diff --git a/lib/rainbows/rev_thread_pool.rb b/lib/rainbows/coolio_thread_pool.rb similarity index 65% copy from lib/rainbows/rev_thread_pool.rb copy to lib/rainbows/coolio_thread_pool.rb index 4366086..d0a359e 100644 --- a/lib/rainbows/rev_thread_pool.rb +++ b/lib/rainbows/coolio_thread_pool.rb @@ -1,8 +1,6 @@ # -*- encoding: binary -*- -# CoolioThreadPool is the new version of this, use that instead. -# -# A combination of the Rev and ThreadPool models. This allows Ruby +# A combination of the Coolio and ThreadPool 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 @@ -10,17 +8,16 @@ # server are handled by the main thread and outside of the core # application dispatch. # -# Unlike ThreadPool, Rev makes this model highly suitable for +# Unlike ThreadPool, Cool.io 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. # # This concurrency model is designed for Ruby 1.9, and Ruby 1.8 # users are NOT advised to use this due to high CPU usage. -module Rainbows::RevThreadPool - +module Rainbows::CoolioThreadPool # :stopdoc: DEFAULTS = { - :pool_size => 20, # same default size as ThreadPool (w/o Rev) + :pool_size => 20, # same default size as ThreadPool (w/o Coolio) } #:startdoc: @@ -30,7 +27,7 @@ module Rainbows::RevThreadPool Integer === o[:pool_size] && o[:pool_size] > 0 or raise ArgumentError, "pool_size must a be an Integer > 0" end - include Rainbows::Rev::Core + include Rainbows::Coolio::Core def init_worker_threads(master, queue) # :nodoc: Rainbows::O[:pool_size].times.map do @@ -47,13 +44,14 @@ module Rainbows::RevThreadPool def init_worker_process(worker) # :nodoc: super - master = Rainbows::Rev::Master.new(Queue.new).attach(Rev::Loop.default) - queue = Rainbows::RevThreadPool::Client.const_set(:QUEUE, Queue.new) + cloop = Coolio::Loop.default + master = Rainbows::Coolio::Master.new(Queue.new).attach(cloop) + queue = Client.const_set(:QUEUE, Queue.new) threads = init_worker_threads(master, queue) - Rainbows::RevThreadPool::Watcher.new(threads).attach(Rev::Loop.default) - logger.info "RevThreadPool pool_size=#{Rainbows::O[:pool_size]}" + Watcher.new(threads).attach(cloop) + logger.info "CoolioThreadPool pool_size=#{Rainbows::O[:pool_size]}" end end # :enddoc: -require 'rainbows/rev_thread_pool/client' -require 'rainbows/rev_thread_pool/watcher' +require 'rainbows/coolio_thread_pool/client' +require 'rainbows/coolio_thread_pool/watcher' diff --git a/lib/rainbows/rev_thread_pool/client.rb b/lib/rainbows/coolio_thread_pool/client.rb similarity index 63% rename from lib/rainbows/rev_thread_pool/client.rb rename to lib/rainbows/coolio_thread_pool/client.rb index c282951..303b8e2 100644 --- a/lib/rainbows/rev_thread_pool/client.rb +++ b/lib/rainbows/coolio_thread_pool/client.rb @@ -1,6 +1,6 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::RevThreadPool::Client < Rainbows::Rev::ThreadClient +class Rainbows::CoolioThreadPool::Client < Rainbows::Coolio::ThreadClient # QUEUE constant will be set in worker_loop def app_dispatch QUEUE << self diff --git a/lib/rainbows/rev_thread_pool/watcher.rb b/lib/rainbows/coolio_thread_pool/watcher.rb similarity index 77% rename from lib/rainbows/rev_thread_pool/watcher.rb rename to lib/rainbows/coolio_thread_pool/watcher.rb index 2419066..9b0e97e 100644 --- a/lib/rainbows/rev_thread_pool/watcher.rb +++ b/lib/rainbows/coolio_thread_pool/watcher.rb @@ -1,6 +1,6 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::RevThreadPool::Watcher < Rev::TimerWatcher +class Rainbows::CoolioThreadPool::Watcher < Coolio::TimerWatcher G = Rainbows::G def initialize(threads) diff --git a/lib/rainbows/coolio_thread_spawn.rb b/lib/rainbows/coolio_thread_spawn.rb index 81591d9..7ea3bda 100644 --- a/lib/rainbows/coolio_thread_spawn.rb +++ b/lib/rainbows/coolio_thread_spawn.rb @@ -1,8 +1,4 @@ # -*- encoding: binary -*- -# :stopdoc: -Rainbows.const_set(:CoolioThreadSpawn, Rainbows::RevThreadSpawn) -# :startdoc: - # A combination of the Coolio 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 @@ -17,4 +13,15 @@ Rainbows.const_set(:CoolioThreadSpawn, Rainbows::RevThreadSpawn) # # This concurrency model is designed for Ruby 1.9, and Ruby 1.8 # users are NOT advised to use this due to high CPU usage. -module Rainbows::CoolioThreadSpawn; end +module Rainbows::CoolioThreadSpawn + include Rainbows::Coolio::Core + + def init_worker_process(worker) # :nodoc: + super + master = Rainbows::Coolio::Master.new(Queue.new) + master.attach(Coolio::Loop.default) + Client.const_set(:MASTER, master) + end +end +# :enddoc: +require 'rainbows/coolio_thread_spawn/client' diff --git a/lib/rainbows/rev_thread_spawn/client.rb b/lib/rainbows/coolio_thread_spawn/client.rb similarity index 69% rename from lib/rainbows/rev_thread_spawn/client.rb rename to lib/rainbows/coolio_thread_spawn/client.rb index 60afc9b..70cff99 100644 --- a/lib/rainbows/rev_thread_spawn/client.rb +++ b/lib/rainbows/coolio_thread_spawn/client.rb @@ -1,6 +1,6 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::RevThreadSpawn::Client < Rainbows::Rev::ThreadClient +class Rainbows::CoolioThreadSpawn::Client < Rainbows::Coolio::ThreadClient # MASTER will be set in worker_loop def app_dispatch Thread.new(self) { |client| MASTER << [ client, app_response ] } diff --git a/lib/rainbows/fiber/coolio.rb b/lib/rainbows/fiber/coolio.rb new file mode 100644 index 0000000..cb602d8 --- /dev/null +++ b/lib/rainbows/fiber/coolio.rb @@ -0,0 +1,12 @@ +# -*- encoding: binary -*- +# :enddoc: +require 'rainbows/coolio_support' +require 'rainbows/fiber' +require 'rainbows/fiber/io' + +module Rainbows::Fiber::Coolio + autoload :Heartbeat, 'rainbows/fiber/coolio/heartbeat' + autoload :Server, 'rainbows/fiber/coolio/server' + autoload :Sleeper, 'rainbows/fiber/coolio/sleeper' +end +require 'rainbows/fiber/coolio/methods' diff --git a/lib/rainbows/fiber/rev/heartbeat.rb b/lib/rainbows/fiber/coolio/heartbeat.rb similarity index 85% rename from lib/rainbows/fiber/rev/heartbeat.rb rename to lib/rainbows/fiber/coolio/heartbeat.rb index f9ef573..f48f7ef 100644 --- a/lib/rainbows/fiber/rev/heartbeat.rb +++ b/lib/rainbows/fiber/coolio/heartbeat.rb @@ -1,6 +1,6 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::Fiber::Rev::Heartbeat < Rev::TimerWatcher +class Rainbows::Fiber::Coolio::Heartbeat < Coolio::TimerWatcher G = Rainbows::G # ZZ gets populated by read_expire in rainbows/fiber/io/methods diff --git a/lib/rainbows/fiber/rev/methods.rb b/lib/rainbows/fiber/coolio/methods.rb similarity index 82% rename from lib/rainbows/fiber/rev/methods.rb rename to lib/rainbows/fiber/coolio/methods.rb index 4421fd3..64b0ee6 100644 --- a/lib/rainbows/fiber/rev/methods.rb +++ b/lib/rainbows/fiber/coolio/methods.rb @@ -1,11 +1,11 @@ # -*- encoding: binary -*- # :enddoc: -module Rainbows::Fiber::Rev::Methods - class Watcher < Rev::IOWatcher +module Rainbows::Fiber::Coolio::Methods + class Watcher < Coolio::IOWatcher def initialize(fio, flag) @f = Fiber.current super(fio, flag) - attach(Rev::Loop.default) + attach(Coolio::Loop.default) end def on_readable @@ -43,5 +43,5 @@ end Rainbows::Fiber::IO::Socket, Rainbows::Fiber::IO::Pipe ].each do |klass| - klass.__send__(:include, Rainbows::Fiber::Rev::Methods) + klass.__send__(:include, Rainbows::Fiber::Coolio::Methods) end diff --git a/lib/rainbows/fiber/rev/server.rb b/lib/rainbows/fiber/coolio/server.rb similarity index 88% rename from lib/rainbows/fiber/rev/server.rb rename to lib/rainbows/fiber/coolio/server.rb index 9998cde..0de1ab3 100644 --- a/lib/rainbows/fiber/rev/server.rb +++ b/lib/rainbows/fiber/coolio/server.rb @@ -1,6 +1,6 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::Fiber::Rev::Server < Rev::IOWatcher +class Rainbows::Fiber::Coolio::Server < Coolio::IOWatcher G = Rainbows::G include Rainbows::ProcessClient diff --git a/lib/rainbows/fiber/rev/sleeper.rb b/lib/rainbows/fiber/coolio/sleeper.rb similarity index 64% rename from lib/rainbows/fiber/rev/sleeper.rb rename to lib/rainbows/fiber/coolio/sleeper.rb index 51f4527..a11623a 100644 --- a/lib/rainbows/fiber/rev/sleeper.rb +++ b/lib/rainbows/fiber/coolio/sleeper.rb @@ -1,11 +1,11 @@ # -*- encoding: binary -*- # :enddoc: -class Rainbows::Fiber::Rev::Sleeper < Rev::TimerWatcher +class Rainbows::Fiber::Coolio::Sleeper < Coolio::TimerWatcher def initialize(seconds) @f = Fiber.current super(seconds, false) - attach(Rev::Loop.default) + attach(Coolio::Loop.default) Fiber.yield end diff --git a/lib/rainbows/fiber/rev.rb b/lib/rainbows/fiber/rev.rb deleted file mode 100644 index 00e439e..0000000 --- a/lib/rainbows/fiber/rev.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding: binary -*- -# :enddoc: -require 'rainbows/coolio_support' -require 'rainbows/fiber' -require 'rainbows/fiber/io' - -module Rainbows::Fiber::Rev - autoload :Heartbeat, 'rainbows/fiber/rev/heartbeat' - autoload :Server, 'rainbows/fiber/rev/server' - autoload :Sleeper, 'rainbows/fiber/rev/sleeper' -end -require 'rainbows/fiber/rev/methods' diff --git a/lib/rainbows/rev.rb b/lib/rainbows/rev.rb index 16d00aa..b0a8940 100644 --- a/lib/rainbows/rev.rb +++ b/lib/rainbows/rev.rb @@ -1,5 +1,5 @@ # -*- encoding: binary -*- -require 'rainbows/coolio_support' +Rainbows.const_set(:Rev, Rainbows::Coolio) # Coolio is the new version of this, use that instead. # # Implements a basic single-threaded event model with @@ -19,29 +19,4 @@ require 'rainbows/coolio_support' # allows the Rack application to process data as it arrives. This # means "rack.input" will be fully buffered in memory or to a # temporary file before the application is entered. - -module Rainbows::Rev - # :stopdoc: - # keep-alive timeout scoreboard - KATO = {} - - # all connected clients - CONN = {} - - if {}.respond_to?(:compare_by_identity) - CONN.compare_by_identity - KATO.compare_by_identity - end - - autoload :Master, 'rainbows/rev/master' - autoload :ThreadClient, 'rainbows/rev/thread_client' - autoload :DeferredChunkResponse, 'rainbows/rev/deferred_chunk_response' - # :startdoc: -end -# :enddoc: -require 'rainbows/rev/heartbeat' -require 'rainbows/rev/server' -require 'rainbows/rev/core' -require 'rainbows/rev/deferred_response' -require 'rainbows/rev/client' -Rainbows::Rev.__send__ :include, Rainbows::Rev::Core +module Rainbows::Rev; end diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb deleted file mode 100644 index 8b3ffa8..0000000 --- a/lib/rainbows/rev/core.rb +++ /dev/null @@ -1,25 +0,0 @@ -# -*- encoding: binary -*- -# :enddoc: -module Rainbows::Rev::Core - include Rainbows::Base - - # runs inside each forked worker, this sits around and waits - # for connections and doesn't die until the parent dies (or is - # given a INT, QUIT, or TERM signal) - def worker_loop(worker) - Rainbows::Response.setup(Rainbows::Rev::Client) - require 'rainbows/rev/sendfile' - Rainbows::Rev::Client.__send__(:include, Rainbows::Rev::Sendfile) - init_worker_process(worker) - mod = Rainbows.const_get(@use) - rloop = Rainbows::Rev::Server.const_set(:LOOP, Rev::Loop.default) - Rainbows::Rev::Client.const_set(:LOOP, rloop) - Rainbows::Rev::Server.const_set(:MAX, @worker_connections) - Rainbows::Rev::Server.const_set(:CL, mod.const_get(:Client)) - Rainbows::EvCore.const_set(:APP, G.server.app) - Rainbows::EvCore.setup - Rainbows::Rev::Heartbeat.new(1, true).attach(rloop) - LISTENERS.map! { |s| Rainbows::Rev::Server.new(s).attach(rloop) } - rloop.run - end -end diff --git a/lib/rainbows/rev_fiber_spawn.rb b/lib/rainbows/rev_fiber_spawn.rb index 8d0d625..52ba2cd 100644 --- a/lib/rainbows/rev_fiber_spawn.rb +++ b/lib/rainbows/rev_fiber_spawn.rb @@ -1,5 +1,5 @@ # -*- encoding: binary -*- -require 'rainbows/fiber/rev' +Rainbows.const_set(:RevFiberSpawn, Rainbows::CoolioFiberSpawn) # CoolioFiberSpawn is the new version of this, use that instead. # @@ -10,19 +10,4 @@ require 'rainbows/fiber/rev' # 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 Rainbows::RevFiberSpawn - - include Rainbows::Base - include Rainbows::Fiber::Rev - - def worker_loop(worker) # :nodoc: - Rainbows::Response.setup(Server) - init_worker_process(worker) - Server.const_set(:MAX, @worker_connections) - Rainbows::Fiber::Base.setup(Server, nil) - Server.const_set(:APP, G.server.app) - Heartbeat.new(1, true).attach(Rev::Loop.default) - LISTENERS.map! { |s| Server.new(s).attach(Rev::Loop.default) } - Rev::Loop.default.run - end -end +module Rainbows::RevFiberSpawn; end diff --git a/lib/rainbows/coolio_thread_spawn.rb b/lib/rainbows/rev_thread_pool.rb similarity index 69% copy from lib/rainbows/coolio_thread_spawn.rb copy to lib/rainbows/rev_thread_pool.rb index 81591d9..844651a 100644 --- a/lib/rainbows/coolio_thread_spawn.rb +++ b/lib/rainbows/rev_thread_pool.rb @@ -1,9 +1,11 @@ # -*- encoding: binary -*- # :stopdoc: -Rainbows.const_set(:CoolioThreadSpawn, Rainbows::RevThreadSpawn) +Rainbows.const_set(:RevThreadPool, Rainbows::CoolioThreadPool) # :startdoc: -# A combination of the Coolio and ThreadSpawn models. This allows Ruby +# CoolioThreadPool is the new version of this, use that instead. +# +# A combination of the Rev and ThreadPool 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 @@ -11,10 +13,10 @@ Rainbows.const_set(:CoolioThreadSpawn, Rainbows::RevThreadSpawn) # server are handled by the main thread and outside of the core # application dispatch. # -# Unlike ThreadSpawn, Cool.io makes this model highly suitable for +# Unlike ThreadPool, 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. # # This concurrency model is designed for Ruby 1.9, and Ruby 1.8 # users are NOT advised to use this due to high CPU usage. -module Rainbows::CoolioThreadSpawn; end +module Rainbows::RevThreadPool; end diff --git a/lib/rainbows/rev_thread_spawn.rb b/lib/rainbows/rev_thread_spawn.rb index f19b68f..09036f2 100644 --- a/lib/rainbows/rev_thread_spawn.rb +++ b/lib/rainbows/rev_thread_spawn.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +Rainbows.const_set(:RevThreadSpawn, Rainbows::CoolioThreadSpawn) # CoolioThreadPool is the new version of this, use that instead. # @@ -16,14 +17,4 @@ # # This concurrency model is designed for Ruby 1.9, and Ruby 1.8 # users are NOT advised to use this due to high CPU usage. -module Rainbows::RevThreadSpawn - include Rainbows::Rev::Core - - def init_worker_process(worker) # :nodoc: - super - master = Rainbows::Rev::Master.new(Queue.new).attach(Rev::Loop.default) - Rainbows::RevThreadSpawn::Client.const_set(:MASTER, master) - end -end -# :enddoc: -require 'rainbows/rev_thread_spawn/client' +module Rainbows::RevThreadSpawn; end -- 2.11.4.GIT