doc: better document :pool_size options
[rainbows.git] / lib / rainbows / xepoll_thread_pool.rb
blobc1605b8c35478e01a200444e5bf2d71d030b4542
1 # -*- encoding: binary -*-
2 require "thread"
3 require "sleepy_penguin"
4 require "raindrops"
6 # This is an edge-triggered epoll concurrency model with blocking
7 # accept() in a (hopefully) native thread.  This is comparable to
8 # ThreadPool and CoolioThreadPool, but is Linux-only and able to exploit
9 # "wake one" accept() behavior of a blocking accept() call when used
10 # with native threads.
12 # This supports streaming "rack.input" and allows +:pool_size+ tuning
13 # independently of +worker_connections+
15 # === Disadvantages
17 # This is only supported under Linux 2.6 kernels.
19 # === Compared to CoolioThreadPool
21 # This does not buffer outgoing responses in userspace at all, meaning
22 # it can lower response latency to fast clients and also prevent
23 # starvation of other clients when reading slow disks for responses
24 # (when combined with native threads).
26 # CoolioThreadPool is likely better for trickling large static files or
27 # proxying responses to slow clients, but this is likely better for fast
28 # clients.
30 # Unlikely CoolioThreadPool, this supports streaming "rack.input" which
31 # is useful for reading large uploads from fast clients.
33 # This exposes no special API or extensions on top of Rack.
35 # === Compared to ThreadPool
37 # This can maintain idle connections without the memory overhead of an
38 # idle Thread.  The cost of handling/dispatching active connections is
39 # exactly the same for an equivalent number of active connections
40 # (but independently tunable).
42 # === :pool_size vs worker_connections
44 # Since +:pool_size+ and +worker_connections+ are independently tunable,
45 # it is possible to get into situations where active connections need
46 # to wait for an idle thread in the thread pool before being processed
48 # In your Rainbows! config block, you may specify a Thread pool size
49 # to limit your application concurrency independently of
50 # worker_connections.
52 #   Rainbows! do
53 #     use :XEpollThreadPool, :pool_size => 50
54 #     worker_connections 100
55 #   end
57 # In extremely rare cases, this may be combined with Rainbows::AppPool
58 # if you have different concurrency capabilities for different parts of
59 # your Rack application.
61 module Rainbows::XEpollThreadPool
62   extend Rainbows::PoolSize
64   # :stopdoc:
65   include Rainbows::Base
67   def init_worker_process(worker)
68     super
69     require "rainbows/xepoll_thread_pool/client"
70     Rainbows::Client.__send__ :include, Client
71   end
73   def worker_loop(worker) # :nodoc:
74     init_worker_process(worker)
75     Client.loop
76   end
77   # :startdoc:
78 end