From 3a250fcfb9fcfa0ab3a8105821e670563025faa4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 27 Dec 2010 07:18:49 +0000 Subject: initial cool.io support Cool.io is the new name for Rev. We'll continue to support Rev until Cool.io breaks backwards compatibility. Rev may not be supported if Cool.io is. --- lib/rainbows.rb | 8 ++++++-- lib/rainbows/app_pool.rb | 3 ++- lib/rainbows/coolio.rb | 2 ++ lib/rainbows/coolio_fiber_spawn.rb | 2 ++ lib/rainbows/coolio_thread_pool.rb | 2 ++ lib/rainbows/coolio_thread_spawn.rb | 2 ++ lib/rainbows/dev_fd_response.rb | 2 +- lib/rainbows/fiber/rev.rb | 7 ++++++- lib/rainbows/http_server.rb | 3 ++- lib/rainbows/max_body.rb | 4 +++- lib/rainbows/rev.rb | 10 ++++++++-- rainbows.gemspec | 3 +++ t/GNUmakefile | 6 +++++- t/simple-http_Coolio.ru | 9 +++++++++ t/simple-http_CoolioFiberSpawn.ru | 10 ++++++++++ t/simple-http_CoolioThreadPool.ru | 9 +++++++++ t/simple-http_CoolioThreadSpawn.ru | 9 +++++++++ t/t0113-rewindable-input-false.sh | 4 +++- t/t0114-rewindable-input-true.sh | 4 +++- t/t9100-thread-timeout.sh | 4 +++- t/t9101-thread-timeout-threshold.sh | 4 +++- t/test-lib.sh | 1 + t/test_isolate.rb | 9 +++++++-- 23 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 lib/rainbows/coolio.rb create mode 100644 lib/rainbows/coolio_fiber_spawn.rb create mode 100644 lib/rainbows/coolio_thread_pool.rb create mode 100644 lib/rainbows/coolio_thread_spawn.rb create mode 100644 t/simple-http_Coolio.ru create mode 100644 t/simple-http_CoolioFiberSpawn.ru create mode 100644 t/simple-http_CoolioThreadPool.ru create mode 100644 t/simple-http_CoolioThreadSpawn.ru diff --git a/lib/rainbows.rb b/lib/rainbows.rb index 1f8b252..dd5a5b2 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -60,7 +60,7 @@ module Rainbows case G.server.use when :FiberPool, :FiberSpawn Rainbows::Fiber.sleep(nr) - when :RevFiberSpawn + when :RevFiberSpawn, :CoolioFiberSpawn Rainbows::Fiber::Rev::Sleeper.new(nr) when :Revactor Actor.sleep(nr) @@ -98,12 +98,16 @@ module Rainbows :Rev => 50, :RevThreadSpawn => 50, :RevThreadPool => 50, + :RevFiberSpawn => 50, + :Coolio => 50, + :CoolioThreadSpawn => 50, + :CoolioThreadPool => 50, + :CoolioFiberSpawn => 50, :EventMachine => 50, :FiberSpawn => 50, :FiberPool => 50, :ActorSpawn => 50, :NeverBlock => 50, - :RevFiberSpawn => 50, }.each do |model, _| u = model.to_s.gsub(/([a-z0-9])([A-Z0-9])/) { "#{$1}_#{$2.downcase!}" } autoload model, "rainbows/#{u.downcase!}" diff --git a/lib/rainbows/app_pool.rb b/lib/rainbows/app_pool.rb index b406b32..44c6bf5 100644 --- a/lib/rainbows/app_pool.rb +++ b/lib/rainbows/app_pool.rb @@ -88,7 +88,8 @@ class Rainbows::AppPool < Struct.new(:pool, :re) # concurrency models self.re ||= begin case env["rainbows.model"] - when :FiberSpawn, :FiberPool, :Revactor, :NeverBlock, :RevFiberSpawn + when :FiberSpawn, :FiberPool, :Revactor, :NeverBlock, + :RevFiberSpawn, :CoolioFiberSpawn self.pool = Rainbows::Fiber::Queue.new(pool) end true diff --git a/lib/rainbows/coolio.rb b/lib/rainbows/coolio.rb new file mode 100644 index 0000000..fb0a305 --- /dev/null +++ b/lib/rainbows/coolio.rb @@ -0,0 +1,2 @@ +# :enddoc: +Rainbows.const_set(:Coolio, Rainbows::Rev) diff --git a/lib/rainbows/coolio_fiber_spawn.rb b/lib/rainbows/coolio_fiber_spawn.rb new file mode 100644 index 0000000..272d111 --- /dev/null +++ b/lib/rainbows/coolio_fiber_spawn.rb @@ -0,0 +1,2 @@ +# :enddoc: +Rainbows.const_set(:CoolioFiberSpawn, Rainbows::RevFiberSpawn) diff --git a/lib/rainbows/coolio_thread_pool.rb b/lib/rainbows/coolio_thread_pool.rb new file mode 100644 index 0000000..acb1bdb --- /dev/null +++ b/lib/rainbows/coolio_thread_pool.rb @@ -0,0 +1,2 @@ +# :enddoc: +Rainbows.const_set(:CoolioThreadPool, Rainbows::RevThreadSpawn) diff --git a/lib/rainbows/coolio_thread_spawn.rb b/lib/rainbows/coolio_thread_spawn.rb new file mode 100644 index 0000000..1ca5c6c --- /dev/null +++ b/lib/rainbows/coolio_thread_spawn.rb @@ -0,0 +1,2 @@ +# :enddoc: +Rainbows.const_set(:CoolioThreadSpawn, Rainbows::RevThreadSpawn) diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb index 67c94d7..175978b 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -53,7 +53,7 @@ class Rainbows::DevFdResponse < Struct.new(:app) # we need to make sure our pipe output is Fiber-compatible case env["rainbows.model"] - when :FiberSpawn, :FiberPool, :RevFiberSpawn + when :FiberSpawn, :FiberPool, :RevFiberSpawn, :CoolioFiberSpawn io.respond_to?(:kgio_wait_readable) or io = Rainbows::Fiber::IO.new(io) when :Revactor diff --git a/lib/rainbows/fiber/rev.rb b/lib/rainbows/fiber/rev.rb index 85d1c5f..be1b3d9 100644 --- a/lib/rainbows/fiber/rev.rb +++ b/lib/rainbows/fiber/rev.rb @@ -1,6 +1,11 @@ # -*- encoding: binary -*- # :enddoc: -require 'rev' +begin + require 'coolio' +rescue LoadError + require 'rev' +end +require 'rev' if defined?(Coolio) require 'rainbows/fiber' require 'rainbows/fiber/io' diff --git a/lib/rainbows/http_server.rb b/lib/rainbows/http_server.rb index 33aa309..d02af72 100644 --- a/lib/rainbows/http_server.rb +++ b/lib/rainbows/http_server.rb @@ -74,7 +74,8 @@ class Rainbows::HttpServer < Unicorn::HttpServer new_defaults = { 'rainbows.model' => (@use = model.to_sym), 'rack.multithread' => !!(model.to_s =~ /Thread/), - 'rainbows.autochunk' => [:Rev,:EventMachine,:NeverBlock].include?(@use), + 'rainbows.autochunk' => [:Coolio,:Rev, + :EventMachine,:NeverBlock].include?(@use), } Rainbows::Const::RACK_DEFAULTS.update(new_defaults) end diff --git a/lib/rainbows/max_body.rb b/lib/rainbows/max_body.rb index 9c9539f..878b04d 100644 --- a/lib/rainbows/max_body.rb +++ b/lib/rainbows/max_body.rb @@ -53,7 +53,9 @@ class Rainbows::MaxBody def self.setup # :nodoc: Rainbows.max_bytes or return case Rainbows::G.server.use - when :Rev, :EventMachine, :NeverBlock, :RevThreadSpawn, :RevThreadPool + when :Rev, :Coolio, :EventMachine, :NeverBlock, + :RevThreadSpawn, :RevThreadPool, + :CoolioThreadSpawn, :CoolioThreadPool return end diff --git a/lib/rainbows/rev.rb b/lib/rainbows/rev.rb index 6ddb130..cb4701b 100644 --- a/lib/rainbows/rev.rb +++ b/lib/rainbows/rev.rb @@ -1,6 +1,12 @@ # -*- encoding: binary -*- -require 'rev' -Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required' +begin + require 'coolio' + Coolio::VERSION >= '1.0.0' or abort 'cool.io >= 1.0.0 is required' +rescue LoadError + require 'rev' + Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required' +end +require 'rev' if defined?(Coolio) # Implements a basic single-threaded event model with # {Rev}[http://rev.rubyforge.org/]. It is capable of handling diff --git a/rainbows.gemspec b/rainbows.gemspec index 6a94bc7..5490824 100644 --- a/rainbows.gemspec +++ b/rainbows.gemspec @@ -49,6 +49,9 @@ Gem::Specification.new do |s| # Revactor depends on Rev, too, 0.3.0 got the ability to attach IOs # s.add_dependency(%q, [">= 0.3.2"]) # + # Cool.io is the new Rev, but it doesn't work with Revactor + # s.add_dependency(%q, [">= 1.0"]) + # # Rev depends on IOBuffer, which got faster in 0.1.3 # s.add_dependency(%q, [">= 0.1.3"]) # diff --git a/t/GNUmakefile b/t/GNUmakefile index 00c887d..0084f3d 100644 --- a/t/GNUmakefile +++ b/t/GNUmakefile @@ -24,6 +24,7 @@ models += WriterThreadSpawn models += ThreadPool models += ThreadSpawn models += Rev +models += Coolio models += EventMachine models += NeverBlock @@ -33,10 +34,13 @@ ifeq ($(RUBY_ENGINE),ruby) ifeq ($(ONENINE),true) models += Revactor models += FiberSpawn - models += RevFiberSpawn models += FiberPool models += RevThreadPool models += RevThreadSpawn + models += RevFiberSpawn + models += CoolioThreadPool + models += CoolioThreadSpawn + models += CoolioFiberSpawn endif endif diff --git a/t/simple-http_Coolio.ru b/t/simple-http_Coolio.ru new file mode 100644 index 0000000..cd9266a --- /dev/null +++ b/t/simple-http_Coolio.ru @@ -0,0 +1,9 @@ +use Rack::ContentLength +use Rack::ContentType +run lambda { |env| + if env['rack.multithread'] == false && env['rainbows.model'] == :Coolio + [ 200, {}, [ env.inspect << "\n" ] ] + else + raise "rack.multithread is true" + end +} diff --git a/t/simple-http_CoolioFiberSpawn.ru b/t/simple-http_CoolioFiberSpawn.ru new file mode 100644 index 0000000..9c39ed4 --- /dev/null +++ b/t/simple-http_CoolioFiberSpawn.ru @@ -0,0 +1,10 @@ +use Rack::ContentLength +use Rack::ContentType +run lambda { |env| + if env['rack.multithread'] == false && + env['rainbows.model'] == :CoolioFiberSpawn + [ 200, {}, [ Thread.current.inspect << "\n" ] ] + else + raise env.inspect + end +} diff --git a/t/simple-http_CoolioThreadPool.ru b/t/simple-http_CoolioThreadPool.ru new file mode 100644 index 0000000..b65357c --- /dev/null +++ b/t/simple-http_CoolioThreadPool.ru @@ -0,0 +1,9 @@ +use Rack::ContentLength +use Rack::ContentType +run lambda { |env| + if env['rack.multithread'] && env['rainbows.model'] == :CoolioThreadPool + [ 200, {}, [ env.inspect << "\n" ] ] + else + raise "rack.multithread is false" + end +} diff --git a/t/simple-http_CoolioThreadSpawn.ru b/t/simple-http_CoolioThreadSpawn.ru new file mode 100644 index 0000000..3c4bcaa --- /dev/null +++ b/t/simple-http_CoolioThreadSpawn.ru @@ -0,0 +1,9 @@ +use Rack::ContentLength +use Rack::ContentType +run lambda { |env| + if env['rack.multithread'] && env['rainbows.model'] == :CoolioThreadSpawn + [ 200, {}, [ env.inspect << "\n" ] ] + else + raise "rack.multithread is false" + end +} diff --git a/t/t0113-rewindable-input-false.sh b/t/t0113-rewindable-input-false.sh index c906106..1ab79bf 100755 --- a/t/t0113-rewindable-input-false.sh +++ b/t/t0113-rewindable-input-false.sh @@ -1,6 +1,8 @@ #!/bin/sh . ./test-lib.sh -skip_models EventMachine NeverBlock Rev RevThreadSpawn RevThreadPool +skip_models EventMachine NeverBlock +skip_models Rev RevThreadSpawn RevThreadPool +skip_models Coolio CoolioThreadSpawn CoolioThreadPool t_plan 4 "rewindable_input toggled to false" diff --git a/t/t0114-rewindable-input-true.sh b/t/t0114-rewindable-input-true.sh index 349449c..7e337ea 100755 --- a/t/t0114-rewindable-input-true.sh +++ b/t/t0114-rewindable-input-true.sh @@ -1,6 +1,8 @@ #!/bin/sh . ./test-lib.sh -skip_models EventMachine NeverBlock Rev RevThreadSpawn RevThreadPool +skip_models EventMachine NeverBlock +skip_models Rev RevThreadSpawn RevThreadPool +skip_models Coolio CoolioThreadSpawn CoolioThreadPool t_plan 4 "rewindable_input toggled to true" diff --git a/t/t9100-thread-timeout.sh b/t/t9100-thread-timeout.sh index 0f802dd..422052e 100755 --- a/t/t9100-thread-timeout.sh +++ b/t/t9100-thread-timeout.sh @@ -1,7 +1,9 @@ #!/bin/sh . ./test-lib.sh case $model in -ThreadSpawn|ThreadPool|RevThreadSpawn|RevThreadPool) ;; +ThreadSpawn|ThreadPool) ;; +RevThreadSpawn|RevThreadPool) ;; +CoolioThreadSpawn|CoolioThreadPool) ;; *) t_info "$0 is only compatible with Thread*"; exit 0 ;; esac diff --git a/t/t9101-thread-timeout-threshold.sh b/t/t9101-thread-timeout-threshold.sh index 99d3f98..7309475 100755 --- a/t/t9101-thread-timeout-threshold.sh +++ b/t/t9101-thread-timeout-threshold.sh @@ -1,7 +1,9 @@ #!/bin/sh . ./test-lib.sh case $model in -ThreadSpawn|ThreadPool|RevThreadSpawn|RevThreadPool) ;; +ThreadSpawn|ThreadPool) ;; +RevThreadSpawn|RevThreadPool) ;; +CoolioThreadSpawn|CoolioThreadPool) ;; *) t_info "$0 is only compatible with Thread*"; exit 0 ;; esac diff --git a/t/test-lib.sh b/t/test-lib.sh index 4f9d4b1..f65adc5 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -200,6 +200,7 @@ req_curl_chunked_upload_err_check () { case $model in Rev) require_check rev Rev::VERSION ;; +Coolio) require_check coolio Coolio::VERSION ;; Revactor) require_check revactor Revactor::VERSION ;; EventMachine) require_check eventmachine EventMachine::VERSION ;; esac diff --git a/t/test_isolate.rb b/t/test_isolate.rb index ad92f72..e49a7ee 100644 --- a/t/test_isolate.rb +++ b/t/test_isolate.rb @@ -23,7 +23,7 @@ Isolate.now!(opts) do gem 'sendfile', '1.0.0' # next Rubinius should support this gem 'iobuffer', '0.1.3' - gem 'rev', '0.3.2' + gem 'cool.io', '1.0.0' gem 'eventmachine', '0.12.10' gem 'sinatra', '1.0.0' @@ -41,4 +41,9 @@ Isolate.now!(opts) do end $stdout.reopen(old_out) -puts Dir["#{path}/gems/*-*/lib"].map { |x| File.expand_path(x) }.join(':') + +# don't load the old Rev if it exists, Cool.io 1.0.0 is compatible with it, +# even for everything Revactor uses. +dirs = Dir["#{path}/gems/*-*/lib"] +dirs.delete_if { |x| x =~ %r{/rev-[\d\.]+/lib} } +puts dirs.map { |x| File.expand_path(x) }.join(':') -- cgit v1.2.3-24-ge0c7