rev: autoload DeferredResponse
[rainbows.git] / Static_Files
blobff27460e5f43b2cca72a6aea72a5081bd506e78c
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.0.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 Revactor, NeverBlock and EventMachine (see below).
29 The sendfile gem is less buggy than current (Ruby 1.9.2-rc1)
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-rc1 (and before) is also
44 subject to hanging indefinitely when a client disconnected prematurely.
45 This issue is fixed in Ruby trunk (July 2010) and will be in the next
46 Ruby 1.9.2 release.
48 \Rainbows! supports IO.copy_stream since v0.93.0
50 == EventMachine FileStreamer
52 EventMachine and NeverBlock users automatically take advantage of
53 the mmap()-based FileStreamer class distributed with EventMachine.
55 \Rainbows! supports EventMachine FileStreamer since v0.4.0
57 == Performance
59 With large files and high-throughput clients, there should be little
60 performance difference compared to optimal C implementation such as
61 nginx and lighttpd.  Ruby runtime overhead matters more when serving
62 slower clients and smaller files.
64 == The Future...
66 Future releases of \Rainbows! will have byte-range support to serve
67 partial and multipart responses, too.  We'll also support an open file
68 cache (similar to nginx) which 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.