1 # -*- encoding: binary -*-
2 require 'sleepy_penguin'
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.
21 module Rainbows::Epoll
23 include Rainbows::Base
25 autoload :Server, 'rainbows/epoll/server'
26 autoload :Client, 'rainbows/epoll/client'
27 autoload :ResponsePipe, 'rainbows/epoll/response_pipe'
28 autoload :ResponseChunkPipe, 'rainbows/epoll/response_chunk_pipe'
30 attr_writer :nr_clients
35 EP.wait(nil, 1000) { |_, obj| obj.epoll_run }
36 while obj = ReRun.shift
39 Rainbows::Epoll::Client.expire
42 Rainbows::Error.listen_loop(e)
43 end while Rainbows.tick || @nr_clients.call > 0
46 def init_worker_process(worker)
48 Rainbows::Epoll.const_set :EP, SleepyPenguin::Epoll.new
49 Rainbows::Client.__send__ :include, Client
52 def worker_loop(worker) # :nodoc:
53 init_worker_process(worker)