about summary refs log tree commit homepage
path: root/lib/rainbows/rev_fiber_spawn.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-12-22 00:32:04 -0800
committerEric Wong <normalperson@yhbt.net>2009-12-22 00:38:04 -0800
commit19960488441651d689259071fa1be4f6957d681b (patch)
tree80c5752ad4484361c74a081d06fb6e43632d860a /lib/rainbows/rev_fiber_spawn.rb
parentee7fe220ccbc991e1e7cbe982caf48e3303274c7 (diff)
downloadrainbows-19960488441651d689259071fa1be4f6957d681b.tar.gz
This is like the traditional FiberSpawn, but more scalable (but
not necessarily faster) as it can use epoll or kqueue.
Diffstat (limited to 'lib/rainbows/rev_fiber_spawn.rb')
-rw-r--r--lib/rainbows/rev_fiber_spawn.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/rainbows/rev_fiber_spawn.rb b/lib/rainbows/rev_fiber_spawn.rb
new file mode 100644
index 0000000..4ce2995
--- /dev/null
+++ b/lib/rainbows/rev_fiber_spawn.rb
@@ -0,0 +1,29 @@
+# -*- encoding: binary -*-
+require 'rainbows/fiber/rev'
+
+module Rainbows
+
+  # A combination of the Rev 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
+  # being Sunshowers-compatible.  Applications are strongly advised to
+  # wrap all slow IO objects (sockets, pipes) using the
+  # Rainbows::Fiber::IO or similar class whenever possible.
+  module RevFiberSpawn
+
+    include Base
+    include Fiber::Rev
+
+    def worker_loop(worker)
+      init_worker_process(worker)
+      Server.const_set(:MAX, @worker_connections)
+      Server.const_set(:APP, G.server.app)
+      Heartbeat.new(1, true).attach(::Rev::Loop.default)
+      kato = Kato.new.attach(::Rev::Loop.default)
+      Rainbows::Fiber::IO.const_set(:KATO, kato)
+      LISTENERS.map! { |s| Server.new(s).attach(::Rev::Loop.default) }
+      ::Rev::Loop.default.run
+    end
+  end
+end