NEWS:

Uncategorized 07 Sep 2005 08:21 am

Incomplete Guide to FastCGI

The Incomplete guide to using FastCGI at DreamHost.

(Some or all of this may pertain equally to other shared hosting environments also.)

It’s Incomplete in that I want to get the few lessons learned out quickly rather than working out the guide in great detail.

Eliminate 500 Server Errors

I’ve gotten rid of my Rails 500 errors. I haven’t seen one in weeks.

1) Download fcgi_handler.rb available in the rails svn:

http://dev.rubyonrails.org/svn/rails/trunk/railties/lib/fcgi_handler.rb

This is post-rails 0.13.1 (as yet unreleased), and you’ll need 0.13 or newer to use it. Specifically, your dispatch.fcgi should include only these lines (uncommented at least):

require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'
RailsFCGIHandler.process!

2) Copy fcgi_handler.rb to your lib directory.

3) There is no step three!

You may see quite a few dispatch.fcgi processes, but they will exit gracefully instead of causing the 500 errors.

Restart your FastCGI Processes

There is the nice way and the effective way:

killall -USR1 dispatch.fcgi
killall -9 dispatch.fcgi

The first method will tell all processes to exit the next time they are called. I’ve found that they tend not to get cleaned up. (More on that later.) If you do this, even if you get a lot of processes running, you’ll find your app is happy and stable. DreamHost has a process sweeper that should clean up if you get too many processes.

The second will nuke them all even if a process is in mid-request. Mua ha ha. Before switching to the new fcgi_handler I did this each morning. Now I haven’t done it in a couple of weeks.

Eliminate Bugs in your App

This is really important. Even a ‘bug’ like not having a robots.txt file at your root can cause server errors, which can damage dispatch.fcgi processes, which then cause 500 errors (if you don’t use the fcgi_handler above).

Search your production.log and eliminate any issues, big or small.

Comments are closed.