Sendfile headers


#1

Last night at our little hack session at John’s, I added the ability to
support X-Accel-Redirect headers for nginx. It would be great if
someone could test this addition with nginx. In config/environment.rb,
put this line inside the config.after_initialize block:

ResponseCache.defaults[:use_x_accel_redirect] = true

Since I have seancribbs.com running the latest and hosted using
Apache/Passenger, I decided to turn on X-Sendfile headers. However,
Apache doesn’t seem to recognize them and just serves up a blank
response (with the X-Sendfile header included in the response). So my
questions are two:

  1. Is this just a side-effect of using Passenger? Would a proxy scenario
    (Mongrel, Thin, etc) work?
  2. Is there something different Radiant should be doing with other
    headers to make it work?

Additionally, if anyone could look into conditional GETs and make sure
we’re doing it right, that would be great.

Sean


#2

It seems my problem is that “EnableSendfile” in Apache core is not the
same thing as X-Sendfile. Installing mod_xsendfile fixes the problem.

That said, anyone who can test with nginx - please report!

Sean


#3

Once a page has comments there is a link in the admin of that page to
view comments and if I click on it I get an application error. This
is what the production log says:

Parameters: {“action”=>“index”, “page_id”=>“5”, “controller”=>“admin/
comments”}
Cookie set: session_token=a7c8382524930cc092981330cf62fc75f8a68582;
path=/; expires=Sat, 14 Feb 2009 00:43:07 GMT
Rendering template within layouts/application
Rendering admin/comments/index

ActionView::TemplateError (undefined method `page_edit_url’ for
#ActionView::Base:0x93fe360) on line #1 of admin/comments/index.rhtml:
1:

<%= @page.nil? ? “#{params[:status].titleize if
params[:status]} Comments” : “#{@page.comments_count}
#{pluralize(@page.comments_count, “Comment”)} on
#{link_to(@page.title, page_edit_url(@page.id))}” %>


2:
3:


4: View:

 vendor/extensions/comments/app/views/admin/comments/index.rhtml:

1:in
_run_erb_47vendor47extensions47comments47app47views47admin47comments47index46rhtml ' vendor/rails/actionpack/lib/action_view/base.rb:342:insend’
vendor/rails/actionpack/lib/action_view/base.rb:342:in execute' vendor/rails/actionpack/lib/action_view/template_handlers/ compilable.rb:29:insend’
vendor/rails/actionpack/lib/action_view/template_handlers/
compilable.rb:29:in render' vendor/rails/actionpack/lib/action_view/template.rb:35:inrender’
vendor/rails/actionpack/lib/action_view/template.rb:22:in
render_template' vendor/rails/actionpack/lib/action_view/base.rb:248:inrender_file’

What do I do about this undefined method ‘page_edit_url’?

Thanks for any help,

Steven


#4

Comments may not have been updated for Radiant 0.7 (which did not
preserve named routes from earlier versions)
I believe it should be edit_admin_page_url now, assuming you are on
edge Radiant.


#5

Sean, did you use my page_attachments_xsendfile extension? If not,
I’m curious how you set it up.

Jason


#6

Jason,

This doesn’t affect page_attachments. For Apache, I compiled and
installed mod_xsendfile, and then added these two directives to my
Apache config:

XSendfile on
XSendFileAllowAbove on

And this line to config/environment.rb, inside the after_initialize
block:

ResponseCache.defaults[:use_x_sendfile] = true

Sean


#7

Thank you Jim. I bet you’re right.

Steven


#8

And did it work in production? When I did exactly that (probably 4
months ago), I found sometimes I would get a blank page or the plain
text version of the cache file. I didn’t have time to figure it out,
so I just turned it off again.


#9

I got blank pages occasionally until I installed mod_xsendfile
properly. Then, It Just Worked™.

Sean


#10

They wouldn’t report a different size (all other headers are preserved),
but the header gives the file a fast-track through the web-server and
operating system. Essentially, it tells the OS to stream the file to
the socket, on OS’s that support it.

Sean


#11

i’ve been using the old x-sendfile patch on nginx and mongrel for about
a
year with no blank page issues. after setting up an edge 0.7 in a
virtual
machine i was able to run nginx and thin in production mode with no
blank
pages in well over a million requests through ab (assuming those blank
pages
would report their size differently than the page that was supposed to
be
served).


#12

I installed on 64-bit Ubuntu 8.10. (seancribbs.com)

Sean


#13

what type of system did you install mod_xsendfile on? it’s completely
broken
for 64bit httpd on osx.