From 8e2e8adda8adbadee8ab31cde700b7e486b1154c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 4 Feb 2011 18:58:26 -0800 Subject: rename XAcceptEpoll to XEpoll It's too long especially since XEpollThreadPool is planned :> --- lib/rainbows.rb | 2 +- lib/rainbows/http_server.rb | 2 +- lib/rainbows/max_body.rb | 2 +- lib/rainbows/xaccept_epoll.rb | 24 --------------- lib/rainbows/xaccept_epoll/client.rb | 60 ------------------------------------ lib/rainbows/xepoll.rb | 24 +++++++++++++++ lib/rainbows/xepoll/client.rb | 60 ++++++++++++++++++++++++++++++++++++ t/GNUmakefile | 2 +- t/simple-http_XAcceptEpoll.ru | 9 ------ t/simple-http_XEpoll.ru | 9 ++++++ t/t0113-rewindable-input-false.sh | 2 +- t/t0114-rewindable-input-true.sh | 2 +- 12 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 lib/rainbows/xaccept_epoll.rb delete mode 100644 lib/rainbows/xaccept_epoll/client.rb create mode 100644 lib/rainbows/xepoll.rb create mode 100644 lib/rainbows/xepoll/client.rb delete mode 100644 t/simple-http_XAcceptEpoll.ru create mode 100644 t/simple-http_XEpoll.ru diff --git a/lib/rainbows.rb b/lib/rainbows.rb index 8271d25..fed0715 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -124,7 +124,7 @@ module Rainbows :CoolioThreadPool => 50, :CoolioFiberSpawn => 50, :Epoll => 50, - :XAcceptEpoll => 50, + :XEpoll => 50, :EventMachine => 50, :FiberSpawn => 50, :FiberPool => 50, diff --git a/lib/rainbows/http_server.rb b/lib/rainbows/http_server.rb index 91c6cad..236c379 100644 --- a/lib/rainbows/http_server.rb +++ b/lib/rainbows/http_server.rb @@ -72,7 +72,7 @@ class Rainbows::HttpServer < Unicorn::HttpServer new_defaults = { 'rainbows.model' => (@use = model.to_sym), 'rack.multithread' => !!(model.to_s =~ /Thread/), - 'rainbows.autochunk' => [:Coolio,:Rev,:Epoll,:XAcceptEpoll, + 'rainbows.autochunk' => [:Coolio,:Rev,:Epoll,:XEpoll, :EventMachine,:NeverBlock].include?(@use), } Rainbows::Const::RACK_DEFAULTS.update(new_defaults) diff --git a/lib/rainbows/max_body.rb b/lib/rainbows/max_body.rb index 68ae3e3..fba8b3c 100644 --- a/lib/rainbows/max_body.rb +++ b/lib/rainbows/max_body.rb @@ -56,7 +56,7 @@ class Rainbows::MaxBody when :Rev, :Coolio, :EventMachine, :NeverBlock, :RevThreadSpawn, :RevThreadPool, :CoolioThreadSpawn, :CoolioThreadPool, - :Epoll, :XAcceptEpoll + :Epoll, :XEpoll return end diff --git a/lib/rainbows/xaccept_epoll.rb b/lib/rainbows/xaccept_epoll.rb deleted file mode 100644 index 94ad332..0000000 --- a/lib/rainbows/xaccept_epoll.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -*- encoding: binary -*- -# :enddoc: -require 'raindrops' -require 'rainbows/epoll' - -# Edge-triggered epoll concurrency model with blocking accept() in -# a (hopefully) native thread. This is recommended over Epoll for -# Ruby 1.9 users as it can workaround accept()-scalability issues -# on multicore machines. -module Rainbows::XAcceptEpoll - include Rainbows::Base - autoload :Client, 'rainbows/xaccept_epoll/client' - - def init_worker_process(worker) - super - Rainbows::Epoll.const_set :EP, SleepyPenguin::Epoll.new - Rainbows::Client.__send__ :include, Client - end - - def worker_loop(worker) # :nodoc: - init_worker_process(worker) - Client.run - end -end diff --git a/lib/rainbows/xaccept_epoll/client.rb b/lib/rainbows/xaccept_epoll/client.rb deleted file mode 100644 index f0fecd0..0000000 --- a/lib/rainbows/xaccept_epoll/client.rb +++ /dev/null @@ -1,60 +0,0 @@ -# -*- encoding: binary -*- -# :enddoc: - -module Rainbows::XAcceptEpoll::Client - include Rainbows::Epoll::Client - MAX = Rainbows.server.worker_connections - THRESH = MAX - 1 - EP = Rainbows::Epoll::EP - N = Raindrops.new(1) - @timeout = Rainbows.server.timeout / 2.0 - THREADS = Rainbows::HttpServer::LISTENERS.map do |sock| - Thread.new(sock) do |sock| - sleep - begin - if io = sock.kgio_accept - N.incr(0, 1) - io.epoll_once - end - sleep while N[0] >= MAX - rescue => e - Rainbows::Error.listen_loop(e) - end while Rainbows.alive - end - end - - def self.run - THREADS.each { |t| t.run } - begin - EP.wait(nil, @timeout) { |flags, obj| obj.epoll_run } - Rainbows::Epoll::Client.expire - rescue Errno::EINTR - rescue => e - Rainbows::Error.listen_loop(e) - end while Rainbows.tick - - THREADS.delete_if do |thr| - Rainbows.tick - begin - thr.run - thr.join(0.01) - rescue - true - end - end until THREADS.empty? - end - - # only call this once - def epoll_once - @wr_queue = [] # may contain String, ResponsePipe, and StreamFile objects - post_init - EP.set(self, IN) # wake up the main thread - rescue => e - Rainbows::Error.write(self, e) - end - - def on_close - KATO.delete(self) - N.decr(0, 1) == THRESH and THREADS.each { |t| t.run } - end -end diff --git a/lib/rainbows/xepoll.rb b/lib/rainbows/xepoll.rb new file mode 100644 index 0000000..3a02b46 --- /dev/null +++ b/lib/rainbows/xepoll.rb @@ -0,0 +1,24 @@ +# -*- encoding: binary -*- +# :enddoc: +require 'raindrops' +require 'rainbows/epoll' + +# Edge-triggered epoll concurrency model with blocking accept() in +# a (hopefully) native thread. This is recommended over Epoll for +# Ruby 1.9 users as it can workaround accept()-scalability issues +# on multicore machines. +module Rainbows::XEpoll + include Rainbows::Base + autoload :Client, 'rainbows/xepoll/client' + + def init_worker_process(worker) + super + Rainbows::Epoll.const_set :EP, SleepyPenguin::Epoll.new + Rainbows::Client.__send__ :include, Client + end + + def worker_loop(worker) # :nodoc: + init_worker_process(worker) + Client.run + end +end diff --git a/lib/rainbows/xepoll/client.rb b/lib/rainbows/xepoll/client.rb new file mode 100644 index 0000000..fa5999b --- /dev/null +++ b/lib/rainbows/xepoll/client.rb @@ -0,0 +1,60 @@ +# -*- encoding: binary -*- +# :enddoc: + +module Rainbows::XEpoll::Client + include Rainbows::Epoll::Client + MAX = Rainbows.server.worker_connections + THRESH = MAX - 1 + EP = Rainbows::Epoll::EP + N = Raindrops.new(1) + @timeout = Rainbows.server.timeout / 2.0 + THREADS = Rainbows::HttpServer::LISTENERS.map do |sock| + Thread.new(sock) do |sock| + sleep + begin + if io = sock.kgio_accept + N.incr(0, 1) + io.epoll_once + end + sleep while N[0] >= MAX + rescue => e + Rainbows::Error.listen_loop(e) + end while Rainbows.alive + end + end + + def self.run + THREADS.each { |t| t.run } + begin + EP.wait(nil, @timeout) { |flags, obj| obj.epoll_run } + Rainbows::Epoll::Client.expire + rescue Errno::EINTR + rescue => e + Rainbows::Error.listen_loop(e) + end while Rainbows.tick + + THREADS.delete_if do |thr| + Rainbows.tick + begin + thr.run + thr.join(0.01) + rescue + true + end + end until THREADS.empty? + end + + # only call this once + def epoll_once + @wr_queue = [] # may contain String, ResponsePipe, and StreamFile objects + post_init + EP.set(self, IN) # wake up the main thread + rescue => e + Rainbows::Error.write(self, e) + end + + def on_close + KATO.delete(self) + N.decr(0, 1) == THRESH and THREADS.each { |t| t.run } + end +end diff --git a/t/GNUmakefile b/t/GNUmakefile index 21b5154..07dfec9 100644 --- a/t/GNUmakefile +++ b/t/GNUmakefile @@ -20,7 +20,7 @@ RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))') export RUBY_VERSION RUBY_ENGINE ifeq (Linux,$(shell uname -s)) - models += XAcceptEpoll + models += XEpoll models += Epoll endif models += WriterThreadPool diff --git a/t/simple-http_XAcceptEpoll.ru b/t/simple-http_XAcceptEpoll.ru deleted file mode 100644 index fc0baa6..0000000 --- a/t/simple-http_XAcceptEpoll.ru +++ /dev/null @@ -1,9 +0,0 @@ -use Rack::ContentLength -use Rack::ContentType -run lambda { |env| - if env['rack.multithread'] == false && env['rainbows.model'] == :XAcceptEpoll - [ 200, {}, [ Thread.current.inspect << "\n" ] ] - else - raise env.inspect - end -} diff --git a/t/simple-http_XEpoll.ru b/t/simple-http_XEpoll.ru new file mode 100644 index 0000000..518099b --- /dev/null +++ b/t/simple-http_XEpoll.ru @@ -0,0 +1,9 @@ +use Rack::ContentLength +use Rack::ContentType +run lambda { |env| + if env['rack.multithread'] == false && env['rainbows.model'] == :XEpoll + [ 200, {}, [ Thread.current.inspect << "\n" ] ] + else + raise env.inspect + end +} diff --git a/t/t0113-rewindable-input-false.sh b/t/t0113-rewindable-input-false.sh index 1119dbf..6eb2fda 100755 --- a/t/t0113-rewindable-input-false.sh +++ b/t/t0113-rewindable-input-false.sh @@ -3,7 +3,7 @@ skip_models EventMachine NeverBlock skip_models Rev RevThreadSpawn RevThreadPool skip_models Coolio CoolioThreadSpawn CoolioThreadPool -skip_models Epoll XAcceptEpoll +skip_models Epoll XEpoll 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 f4ef796..9d256dc 100755 --- a/t/t0114-rewindable-input-true.sh +++ b/t/t0114-rewindable-input-true.sh @@ -3,7 +3,7 @@ skip_models EventMachine NeverBlock skip_models Rev RevThreadSpawn RevThreadPool skip_models Coolio CoolioThreadSpawn CoolioThreadPool -skip_models Epoll XAcceptEpoll +skip_models Epoll XEpoll t_plan 4 "rewindable_input toggled to true" -- cgit v1.2.3-24-ge0c7