epoll: ensure closing of pipelined clients if required
[rainbows.git] / Static_Files
blob3ced433fbac25a80c9bcecb21c84477b907a0270
1 = Static file serving with \Rainbows!
3 While Ruby application servers aren't traditionally used to serve static
4 files, it'll be fun for us to see how far we can go with \Rainbows!
6 We aren't delusional enough (yet :) to compete with C-based servers like
7 nginx or lighttpd in terms of raw performance, but wouldn't it be nice
8 to simplify your deployments and only deploy one server?
10 == {sendfile}[http://rubygems.org/gems/sendfile] RubyGem
12 To enable the "sendfile" gem, just make sure you have 1.1.0 or later and
13 "require" it in your \Rainbows!/Unicorn config file (not your Rack
14 config.ru):
16     require 'sendfile' # that's it! nothing else to do
18     # the rest of you Rainbows! config goes below:
19     worker_processes 4
20     stderr_path "/var/log/app/rainbows.err.log"
21     Rainbows! do
22       use :RevFiberSpawn
23       worker_connections 100
24     end
26 The sendfile gem is works for all of our concurrency models except
27 NeverBlock and EventMachine (see below).
29 The sendfile gem is less buggy than current (Ruby 1.9.2)
30 IO.copy_stream and supports FreeBSD and Solaris in addition to Linux.
31 This RubyGem also works under Ruby 1.8 (even with threads) and should
32 work with rubinius.git, too.
34 \Rainbows! supports the sendfile gem since v0.95.0
36 == IO.copy_stream (Ruby 1.9 only)
38 Users of pure-Ruby Thread-based models ThreadPool, ThreadSpawn, and
39 their Writer* variants use the core IO.copy_stream method under Ruby
40 1.9.  IO.copy_stream uses sendfile() under Linux, and a pread()/write()
41 loop (implemented in C) on other systems.
43 IO.copy_stream under Linux with Ruby 1.9.2 (and before) is also
44 subject to hanging indefinitely when a client disconnected prematurely.
45 This issue is fixed in Ruby trunk (r28557, July 2010).
47 \Rainbows! supports IO.copy_stream since v0.93.0
49 == EventMachine FileStreamer
51 EventMachine and NeverBlock users automatically take advantage of the
52 mmap()-based FileStreamer class distributed with EventMachine.
53 Unfortunately, as of EventMachine 0.12.10, FileStreamer cannot easily
54 support HTTP Range responses.
56 \Rainbows! supports EventMachine FileStreamer since v0.4.0
58 == Performance
60 With large files and high-throughput clients, there should be little
61 performance difference compared to optimal C implementation such as
62 nginx and lighttpd.  Ruby runtime overhead matters more when serving
63 slower clients and smaller files.
65 == The Future...
67 We'll also support an open file cache (similar to nginx) which
68 allows us to reuse open file descriptors.
70 Under Linux, we'll support the splice(2) system call for zero-copy
71 proxying {io_splice}[http://bogomips.org/ruby_io_splice/], too.