about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--TODO4
-rw-r--r--lib/rainbows.rb4
-rw-r--r--lib/rainbows/coolio.rb30
-rw-r--r--lib/rainbows/coolio/client.rb (renamed from lib/rainbows/rev/client.rb)18
-rw-r--r--lib/rainbows/coolio/core.rb25
-rw-r--r--lib/rainbows/coolio/deferred_chunk_response.rb (renamed from lib/rainbows/rev/deferred_chunk_response.rb)5
-rw-r--r--lib/rainbows/coolio/deferred_response.rb (renamed from lib/rainbows/rev/deferred_response.rb)4
-rw-r--r--lib/rainbows/coolio/heartbeat.rb (renamed from lib/rainbows/rev/heartbeat.rb)8
-rw-r--r--lib/rainbows/coolio/master.rb (renamed from lib/rainbows/rev/master.rb)2
-rw-r--r--lib/rainbows/coolio/sendfile.rb (renamed from lib/rainbows/rev/sendfile.rb)2
-rw-r--r--lib/rainbows/coolio/server.rb (renamed from lib/rainbows/rev/server.rb)4
-rw-r--r--lib/rainbows/coolio/thread_client.rb (renamed from lib/rainbows/rev/thread_client.rb)6
-rw-r--r--lib/rainbows/coolio_fiber_spawn.rb21
-rw-r--r--lib/rainbows/coolio_support.rb1
-rw-r--r--lib/rainbows/coolio_thread_pool.rb45
-rw-r--r--lib/rainbows/coolio_thread_pool/client.rb (renamed from lib/rainbows/rev_thread_pool/client.rb)2
-rw-r--r--lib/rainbows/coolio_thread_pool/watcher.rb (renamed from lib/rainbows/rev_thread_pool/watcher.rb)2
-rw-r--r--lib/rainbows/coolio_thread_spawn.rb17
-rw-r--r--lib/rainbows/coolio_thread_spawn/client.rb (renamed from lib/rainbows/rev_thread_spawn/client.rb)2
-rw-r--r--lib/rainbows/fiber/coolio.rb12
-rw-r--r--lib/rainbows/fiber/coolio/heartbeat.rb (renamed from lib/rainbows/fiber/rev/heartbeat.rb)2
-rw-r--r--lib/rainbows/fiber/coolio/methods.rb (renamed from lib/rainbows/fiber/rev/methods.rb)8
-rw-r--r--lib/rainbows/fiber/coolio/server.rb (renamed from lib/rainbows/fiber/rev/server.rb)2
-rw-r--r--lib/rainbows/fiber/coolio/sleeper.rb (renamed from lib/rainbows/fiber/rev/sleeper.rb)4
-rw-r--r--lib/rainbows/fiber/rev.rb12
-rw-r--r--lib/rainbows/rev.rb29
-rw-r--r--lib/rainbows/rev/core.rb25
-rw-r--r--lib/rainbows/rev_fiber_spawn.rb19
-rw-r--r--lib/rainbows/rev_thread_pool.rb45
-rw-r--r--lib/rainbows/rev_thread_spawn.rb13
30 files changed, 183 insertions, 190 deletions
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/coolio.rb b/lib/rainbows/coolio.rb
index 2fdc741..a9075cc 100644
--- a/lib/rainbows/coolio.rb
+++ b/lib/rainbows/coolio.rb
@@ -1,7 +1,5 @@
 # -*- encoding: binary -*-
-# :stopdoc:
-Rainbows.const_set(:Coolio, Rainbows::Rev)
-# :startdoc:
+require 'rainbows/coolio_support'
 
 # Implements a basic single-threaded event model with
 # {Cool.io}[http://coolio.github.com/].  It is capable of handling
@@ -20,4 +18,28 @@ Rainbows.const_set(:Coolio, Rainbows::Rev)
 # 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::Coolio; end
+module Rainbows::Coolio
+  # :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/coolio/master'
+  autoload :ThreadClient, 'rainbows/coolio/thread_client'
+  autoload :DeferredChunkResponse, 'rainbows/coolio/deferred_chunk_response'
+  # :startdoc:
+end
+# :enddoc:
+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
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
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
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
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
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
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
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
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/coolio_fiber_spawn.rb b/lib/rainbows/coolio_fiber_spawn.rb
index 6e573b4..9c5af5f 100644
--- a/lib/rainbows/coolio_fiber_spawn.rb
+++ b/lib/rainbows/coolio_fiber_spawn.rb
@@ -1,7 +1,5 @@
 # -*- encoding: binary -*-
-# :stopdoc:
-Rainbows.const_set(:CoolioFiberSpawn, Rainbows::RevFiberSpawn)
-# :startdoc:
+require 'rainbows/fiber/coolio'
 
 # A combination of the Coolio and FiberSpawn models.  This allows Ruby
 # 1.9 Fiber-based concurrency for application processing while
@@ -10,4 +8,19 @@ Rainbows.const_set(:CoolioFiberSpawn, Rainbows::RevFiberSpawn)
 # being Sunshowers-compatible.  Applications are strongly advised to
 # wrap all slow IO objects (sockets, pipes) using the
 # Rainbows::Fiber::IO or a Cool.io-compatible class whenever possible.
-module Rainbows::CoolFiberSpawn; end
+module Rainbows::CoolioFiberSpawn
+
+  include Rainbows::Base
+  include Rainbows::Fiber::Coolio
+
+  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(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/coolio_thread_pool.rb b/lib/rainbows/coolio_thread_pool.rb
index f96795e..d0a359e 100644
--- a/lib/rainbows/coolio_thread_pool.rb
+++ b/lib/rainbows/coolio_thread_pool.rb
@@ -1,7 +1,4 @@
 # -*- encoding: binary -*-
-# :stopdoc:
-Rainbows.const_set(:CoolioThreadPool, Rainbows::RevThreadSpawn)
-# :startdoc:
 
 # A combination of the Coolio and ThreadPool models.  This allows Ruby
 # Thread-based concurrency for application processing.  It DOES NOT
@@ -17,4 +14,44 @@ Rainbows.const_set(:CoolioThreadPool, 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::CoolThreadPool; end
+module Rainbows::CoolioThreadPool
+  # :stopdoc:
+  DEFAULTS = {
+    :pool_size => 20, # same default size as ThreadPool (w/o Coolio)
+  }
+  #:startdoc:
+
+  def self.setup # :nodoc:
+    o = Rainbows::O
+    DEFAULTS.each { |k,v| o[k] ||= v }
+    Integer === o[:pool_size] && o[:pool_size] > 0 or
+      raise ArgumentError, "pool_size must a be an Integer > 0"
+  end
+  include Rainbows::Coolio::Core
+
+  def init_worker_threads(master, queue) # :nodoc:
+    Rainbows::O[:pool_size].times.map do
+      Thread.new do
+        begin
+          client = queue.pop
+          master << [ client, client.app_response ]
+        rescue => e
+          Rainbows::Error.listen_loop(e)
+        end while true
+      end
+    end
+  end
+
+  def init_worker_process(worker) # :nodoc:
+    super
+    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)
+    Watcher.new(threads).attach(cloop)
+    logger.info "CoolioThreadPool pool_size=#{Rainbows::O[:pool_size]}"
+  end
+end
+# :enddoc:
+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
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
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
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
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
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
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
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/rev_thread_pool.rb b/lib/rainbows/rev_thread_pool.rb
index 4366086..844651a 100644
--- a/lib/rainbows/rev_thread_pool.rb
+++ b/lib/rainbows/rev_thread_pool.rb
@@ -1,4 +1,7 @@
 # -*- encoding: binary -*-
+# :stopdoc:
+Rainbows.const_set(:RevThreadPool, Rainbows::CoolioThreadPool)
+# :startdoc:
 
 # CoolioThreadPool is the new version of this, use that instead.
 #
@@ -16,44 +19,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::RevThreadPool
-
-  # :stopdoc:
-  DEFAULTS = {
-    :pool_size => 20, # same default size as ThreadPool (w/o Rev)
-  }
-  #:startdoc:
-
-  def self.setup # :nodoc:
-    o = Rainbows::O
-    DEFAULTS.each { |k,v| o[k] ||= v }
-    Integer === o[:pool_size] && o[:pool_size] > 0 or
-      raise ArgumentError, "pool_size must a be an Integer > 0"
-  end
-  include Rainbows::Rev::Core
-
-  def init_worker_threads(master, queue) # :nodoc:
-    Rainbows::O[:pool_size].times.map do
-      Thread.new do
-        begin
-          client = queue.pop
-          master << [ client, client.app_response ]
-        rescue => e
-          Rainbows::Error.listen_loop(e)
-        end while true
-      end
-    end
-  end
-
-  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)
-    threads = init_worker_threads(master, queue)
-    Rainbows::RevThreadPool::Watcher.new(threads).attach(Rev::Loop.default)
-    logger.info "RevThreadPool pool_size=#{Rainbows::O[:pool_size]}"
-  end
-end
-# :enddoc:
-require 'rainbows/rev_thread_pool/client'
-require 'rainbows/rev_thread_pool/watcher'
+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