Topic: RoR + Apache 2.2 + FCGI = Slow?

I am currently learning the language by following along with the "Pragmatic Rails" book and I must say that I am loving it so far. There is only one quirk that has been bothering me so far. Originally, I had it running on WeBrick via an Apache proxy forward (for seamless integration with current PHP-based site) but I hated having to restart the server every time I made a change. I then discovered the FastCGI module and thought it would be the perfect solution. I downloaded the module and got it up and running on my dev box. It works great but it is slow as molasses. Is there any way to speed it up?

Developement machine specs:
Windows XP Pro x64 Ed. SP2
Apache 2.2.4 w/ mod_fcgi
Latest versions of Ruby & Rails
MySQL 5.0.41
Intel Pentium D 820
2GB DDRII SDRAM
20GB SCSI HDD for x64
40GB IDE HDD for x86
120GB SATA HDD for common/shared data

Btw I made almost no changes to the RoR app (Depot) other than uncommenting a few lines in .htaccess.

Re: RoR + Apache 2.2 + FCGI = Slow?

Is FastCGI running?

1. Install Apache2 web server. Install the Apache 2.0.x version. Apache 2.2.x version does not include the FastCGI module.

2. Install RubyForApache
3. Modify the httpd.conf file in the conf directory. Uncomment  the following line:

        LoadModule rewrite_module modules/mod_rewrite.so

       Add the following line.

         LoadModule fastcgi_module modules/mod_fastcgi.so

4.         
5.    In the httpd.conf configuration file modify the DocumentRoot  directive to the following.

         DocumentRoot "C:/ruby/catalog/public"

              Modify the following line:

               <Directory "C:/Program Files/Apache Group/Apache2/htdocs">

               to:

               <Directory "C:/ruby/catalog/public/">
6.     Add the following VirtualHost element to the bottom of the httpd.conf file.

                  <VirtualHost *:80>
                        ServerName rails
                        DocumentRoot "C:/ruby/catalog/public"
                       <Directory "C:/ruby/catalog/public/">
                             Options ExecCGI FollowSymLinks
                             AllowOverride all
                             Allow from all
                             Order allow,deny
                             AddHandler cgi-script .cgi
                            AddHandler fastcgi-script .fcgi
                       </Directory>
                  </VirtualHost>


Restart the Apache2 web server.

7. In the public/.htaccess file replace

       RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

with:

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Add the comment character to the Apache options.

#AddHandler fastcgi-script .fcgi
#AddHandler cgi-script .cgi
#Options +FollowSymLinks +ExecCGI

Re: RoR + Apache 2.2 + FCGI = Slow?

I have done all of that except for #7. I'll what happens, though.

Btw: Yes, there is an FCGI module for 2.2.4, just Google it. I got mine from Apache Lounge.

Re: RoR + Apache 2.2 + FCGI = Slow?

Without
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

FCGI won't get started.

Re: RoR + Apache 2.2 + FCGI = Slow?

I have been banging my head against the wall trying to figure out how to get FCGI working and I am about to give up. When I use "dispatch.fcgi", rather then processing it the source is spit back out at me. I have tried every solution that I can find but to no avail. I know that mod_fcgid is loaded because it crashed Apache when I accidentally mis-configured my vhost. It just doesn't make sense that it is not parsing the file properly.

Re: RoR + Apache 2.2 + FCGI = Slow?

have you tried reloading fcgi?

go to dispatch.fcgi and change "RailsFCGIHandler.process!" to "RailsFCGIHandler.process! nil, 1". Go back to your page and refresh... wait for it to load and then go back into dispatch.fcgi and change the line back. Worked for me smile

Re: RoR + Apache 2.2 + FCGI = Slow?

I give up. No matter what I do, I just can not get it to work. Thanks, though, for your suggestion, Rudi.

Re: RoR + Apache 2.2 + FCGI = Slow?

Ok; I decided to play around a bit more. This time I kept a close eye on Apache's error log. Can you guys make sense of it?

With the default shebang line:

[Fri Jun 22 21:19:31 2007] [warn] (OS 109)The pipe has been ended.  : mod_fcgid: get overlap result error
[Fri Jun 22 21:19:31 2007] [error] [client 127.0.0.1] Premature end of script headers: dispatch.fcgi
[Fri Jun 22 21:19:32 2007] [warn] (OS 109)The pipe has been ended.  : mod_fcgid: get overlap result error
[Fri Jun 22 21:19:32 2007] [error] [client 127.0.0.1] Premature end of script headers: dispatch.fcgi
[Fri Jun 22 21:21:39 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:39 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:40 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:40 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:41 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:41 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:42 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:42 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:43 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:43 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:44 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:44 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:45 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:45 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:46 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:46 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:47 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:47 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:48 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:48 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:49 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:49 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:50 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:50 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:51 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:51 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:52 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:52 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:53 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:53 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:54 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:54 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:55 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:55 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:56 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:56 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:57 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:57 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:58 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:58 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:21:59 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:59 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:00 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:00 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:01 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:01 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:02 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:02 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:03 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:03 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:04 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:04 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:05 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:05 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:06 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:06 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:07 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:07 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:08 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:08 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:09 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:09 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:10 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:10 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:11 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:11 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:12 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:12 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:13 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:13 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:14 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:14 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:15 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:15 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:16 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:16 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:17 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:17 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:18 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:18 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:19 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:19 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:20 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:20 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:21 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:21 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:22 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:22 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:23 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:23 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:24 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:24 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:25 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:25 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:26 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:26 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:27 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:27 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:28 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:28 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:29 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:29 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:30 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:30 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:31 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:31 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error
[Fri Jun 22 21:22:32 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:22:32 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error

With "d:/ruby/bin/ruby.exe" as the shebang:
[Fri Jun 22 21:25:50 2007] [warn] (OS 109)The pipe has been ended.  : mod_fcgid: get overlap result error
[Fri Jun 22 21:25:50 2007] [error] [client 127.0.0.1] Premature end of script headers: dispatch.fcgi
[Fri Jun 22 21:25:51 2007] [warn] (OS 109)The pipe has been ended.  : mod_fcgid: get overlap result error
[Fri Jun 22 21:25:51 2007] [error] [client 127.0.0.1] Premature end of script headers: dispatch.fcgi

It's also the same if I use back slashes and/or add a "w" to "ruby" as several sites suggested.

Re: RoR + Apache 2.2 + FCGI = Slow?

I am having exactly the same issues as BluDragon.

I'm running Xampp on WindowsXP SP2 with Apache2.2.6, PHP5, MySQL5 and have tried to install mod_fcgid v2.2.

My http.conf has the following line included:

LoadModule fastcgi_module modules/mod_fcgid.so

My applications .htaccess has these lines included:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
AddHandler fcgid-script .fcgi

The application i'm running works perfectly when switching back to regular CGI but is extremely slow. It takes like 30s to load the login page on localhost which is rediculous.

I had hoped switching to fastcgi might help (still don't know if that's correct) but whenever that's being used my application doesn't work and the apache error log shows lines like:

(OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
(OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process c:/ruby/bin/ruby error

So yeah...essentially identical problem as BluDragon.

Can anyone help please? I've tried everything!

Re: RoR + Apache 2.2 + FCGI = Slow?

[Fri Jun 22 21:21:50 2007] [error] (OS 2)The system cannot find the file specified.  : mod_fcgid: can't create process
[Fri Jun 22 21:21:50 2007] [warn] (OS 2)The system cannot find the file specified.  : mod_fcgid: spawn process d:/ruby/bin/ruby error

From those two errors in the log it looks like the fcgi module either can not find the ruby.exe program on your windows computer or it does not have access to be able to execute it.

Can you go to a command line and type "d:\ruby\bin\ruby -v" and get a version number of ruby back?  If not, this is your problem.

Mikel

Re: RoR + Apache 2.2 + FCGI = Slow?

Hi Mikel, thanks for your reply.

In my case yes I can run c:\ruby\bin\ruby -v fine from a command prompt. My dispatch.cgi file works fine with this shebang line also, just dispatch.fcgi returns those errors.

Re: RoR + Apache 2.2 + FCGI = Slow?

MarkOs: Long shot... but are the file permissions for dispatch.fcgi and dispatch.cgi the same?  They should both be executable...

check it out.

Mikel