Forum: Ruby on Rails ActionController#send_file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jon S. (Guest)
on 2006-01-12 16:44
(Received via mailing list)
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
Tom F. (Guest)
on 2006-01-12 20:59
(Received via mailing list)
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!
Jon S. (Guest)
on 2006-01-12 21:17
(Received via mailing list)
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
This topic is locked and can not be replied to.