Burn My Time

~Josh Houghtelin

Rails on FastCGI. It makes a difference.

Josh Houghtelin Software, BSD

This simple rails app using standard CGI on Apache2

The same simple rails app using fastCGI on Apache2

We went from around a second of execution time down to around a tenth of a second. FastCGI obviously a bunch faster. On average for this teeny query it was half a second faster.

Now to install FastCGI.
The FastCGI_Mod seems to be in the ports collection but I went ahead n’ got the source anyway.

Installing FastCGI application
wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar -xvzf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
make
make install

Then we get the apache mod.

wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar -xvzf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2

Here is where I started to have problems. I followed instructions for Apache2 and did

cp Makefile.AP2 Makefile
Make
“Makefile”, line 12: Could not find /usr/local/apache2/build/special.mk
make: fatal errors encountered — cannot continue

Joy. I went & found special.mk and adjusted the Makefile in Vi to represent it’s location in
/usr/local/share/apache2/build/special.mk
Make
It blew up again with a bunch of errors this time so I gave up on running make. Instead, this guy has an easier solution.

apxs -n mod_fastcgi -i -a -c mod_fastcgi.c fcgi_buf.c fcgi_config.c fcgi_pm.c fcgi_protocol.c fcgi_util.c

/usr/local/sbin/apachectl graceful
Syntax error on line 275 of /usr/local/etc/apache2/httpd.conf:
Can’t locate API module structure `mod_fastcgi_module’ in file /usr/local/libexec/apache2/mod_fastcgi.so: Undefined symbol “mod_fastcgi_module”

Another problem. For this, I just edited my httpd.conf file and removed the mod_ on mod_fastcgi_module so now it looks like this.

LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so

And since the httpd.conf is open I added a few other requirements.

AddHandler fastcgi-script .fcgi
and altered “Options Indexes FollowSymLinks” to be
Options Indexes ExecCGI FollowSymLinks

/usr/local/sbin/apachectl graceful

SUCCESS!

Now install the fcgi gem. You may not need the extra syntax but my install botched w/out it.

gem install fcgi — –with-fcgi-include=/usr/local/include –with-fcgi-lib=/usr/local/lib

Now all I had to do was edit the public/.htaccess file

RewriteRule ^(.*)$ /dispatch.cgi?$1 [QSA,L]
to be (just add the f in .fcgi)
RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]

From here things started working just fine. Unfortunately I tried installing FastCGI before and although I got this far, it didn’t seem to want to work correctly.

I was reading this guide and they suggest you edit public/dispatch.fcgi

Remove this line
require ‘fcgi’

Add the following lines
require ‘rubygems’
require_gem ‘fcgi’

it seems that “require ‘fcgi’” is already in the fcgi_handler.rb file. I’m not quite sure where the rest comes into play. Either way, it works for me with or without those last changes.

2 comments

eep. png’s man, not jpeg’s! Those aren’t pictures.

Posted by Blayne, on December 13th, 2005, às 5:42 pm. #.

er. I guess it’s the resizing that’s messing it up.

Posted by Blayne, on December 13th, 2005, às 5:43 pm. #.

Leave a comment!



Message



Burn My Time © 2007.

Simple Grey theme developed by Rodrigo P. Ghedin.
Brought by Wordpress Themes

WordPressFAMFAMFAM