use and recommend sleepy_penguin 3.0.1
[rainbows.git] / lib / rainbows / epoll.rb
blob7b49e67b98d87df35587b15910ec5d68ccc4b998
1 # -*- encoding: binary -*-
2 require 'sleepy_penguin'
3 require 'sendfile'
5 # Edge-triggered epoll concurrency model using
6 # {sleepy_penguin}[http://bogomips.org/sleepy_penguin/] for epoll.
8 # Unlike more portable options like Coolio and EventMachine, this
9 # is Linux-only, but uses edge-triggering instead of level-triggering,
10 # so it may perform better in some cases.  Coolio and EventMachine have
11 # better library support and may be widely-used, however.
13 # Consider using XEpoll instead of this if you are using Ruby 1.9,
14 # it will avoid accept()-scalability issues with many worker processes.
16 # When serving static files, this is extremely unfair and optimized
17 # for throughput at the expense of fairness.  This is not an issue
18 # if you're not serving static files, or if your working set is
19 # small enough to aways be in your kernel page cache.  This concurrency
20 # model may starve clients if you have slow disks and large static files.
22 # === RubyGem Requirements
24 # * raindrops 0.6.0 or later
25 # * sleepy_penguin 3.0.1 or later
26 # * sendfile 1.1.0 or later
28 module Rainbows::Epoll
29   # :stopdoc:
30   include Rainbows::Base
31   autoload :Server, 'rainbows/epoll/server'
32   autoload :Client, 'rainbows/epoll/client'
33   autoload :ResponsePipe, 'rainbows/epoll/response_pipe'
34   autoload :ResponseChunkPipe, 'rainbows/epoll/response_chunk_pipe'
36   def init_worker_process(worker)
37     super
38     Rainbows.const_set(:EP, SleepyPenguin::Epoll.new)
39     Rainbows::Client.__send__ :include, Client
40     LISTENERS.each { |io| io.extend(Server) }
41   end
43   def worker_loop(worker) # :nodoc:
44     init_worker_process(worker)
45     Client.loop
46   end
47   # :startdoc:
48 end