ActionController#send_file


#1

Looking at the code for ActionController#send_file I see that it is
using ruby to send the file contents. Linux supports a sendfile() OS
call. The implementation of Linux sendfile() is extremely fast and
very CPU efficient, far faster than what can be done in user space.

Does Windows support a sendfile() equivalent call? I haven’t been
working with ruby long enough to know how it handles things like this
on a per platform basis, how is it done?


Jon S.
removed_email_address@domain.invalid


#2

The rails send_file method does not use the OS sendfile() call. It
opens
the file, reads in a buffer full (default is 4K), and writes it out to
the
client.

I don’t know if the CGI, FCGI, SCGI protocols have a way for an
application
to return a filename to the web server, and have it send the file using
OS
level calls. I’m guessing this is hard, since at least FCGI apps may
not
even be running on the same machine!


#3

On 1/12/06, Tom F. removed_email_address@domain.invalid wrote:

The rails send_file method does not use the OS sendfile() call. It opens
the file, reads in a buffer full (default is 4K), and writes it out to the
client.

I don’t know if the CGI, FCGI, SCGI protocols have a way for an application
to return a filename to the web server, and have it send the file using OS
level calls. I’m guessing this is hard, since at least FCGI apps may not
even be running on the same machine!

The rails app would call Linux sendfile() directly, there should be no
need to involve the web server. Linux sendfile() only need a handle
for the network socket and a handle for the file. Rails should have
both of these. First Rails would write out the HTTP headers to the
socket and then call sendfile() to send the rest of the file.

But I don’t know enough about how FCGI is implemented, does Rail have
a socket handle directly to the client or is it a socket to the server
which then forwards the data to the client. Either way sendfile()
should be a win since it will reduce the CPU usage of the rails app.

using ruby to send the file contents. Linux supports a sendfile() OS


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Jon S.
removed_email_address@domain.invalid