Prev | Current Page 152 | Next

Brad Ediger

"Advanced Rails"


??? Physical files can be shared with NFS or AFS, put on a MogileFS host, or otherwise
clustered. Achieving high availability or load balancing with database large
objects can be tricky.
??? Any other utility that works on files will have to be integrated or otherwise modified
to work from a database.
104 | Chapter 4: Database
Why Is Filesystem Storage So Fast?
The short answer is that web servers are optimized for throwing binary files down a
TCPsocket. And the most common thing you do with binary files is throw them down
a TCP socket.
Long answer: the secret to this performance, under Linux and various BSDs, is the kernel
sendfile( ) syscall (not to be confused with X-Sendfile, discussed later). The sendfile( )
function copies data quickly from a file descriptor (which represents an open file) to a
socket (which is connected to the client). This happens in kernel mode, not user mode??”
the entire process is handled by the operating system. The web server doesn??™t even have
to think about it. When sendfile( ) is invoked, the process looks a bit like Figure 4-1.
On the other hand, Rails is necessarily involved with the whole process when reading data
from the database. The file must be passed, chunk by chunk, from the database to Rails,
which creates a response and sends the whole thing (including the file) to the web server.
The web server then sends the response to the client.


Pages:
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164