Idle Apache+FastCGI sleeping?

Wondering: Does Apache shut down inactive FastCGI processes if it
doesn’t get any requests for a while? My app works fine if it’s being
used regularly, but it will respond very slowly to the first request
after an hour of zero traffic.

Is there a way to keep FastCGI ready all the time, even when there
haven’t been any requests for a while? We’re deploying this app on a
kiosk, so traffic is very low, but it needs to respond quickly at any
time.

System:

  • Windows XP (I know…)
  • Apache 2.0.55 + FastCGI
  • Ruby 1.8.2
  • RubyForApache-1.3.1
  • Rails 1.0

From httpd.conf:

<VirtualHost *:80>
ServerName rails
DocumentRoot “approot/rails/public”
<Directory “approot/rails/public”>
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from localhost 127.0.0.1
Order allow,deny
AddHandler fastcgi-script .fcgi

FastCgiConfig -initial-env RAILS_ENV=production -maxProcesses=1

Am I missing anything?


Jason A.on
http://www.thenewjhp.com

Am Mittwoch, den 11.01.2006, 13:49 -0800 schrieb Jason A.on:

System:
ServerName rails
FastCgiConfig -initial-env RAILS_ENV=production -maxProcesses=1

Am I missing anything?

Hi,

try to start the FCGI process at Apache startup. Replace your
FastCgiConfig line with the following:

FastCgiServer /var/www/myrailsapp/public/dispatch.fcgi -initial-env
RAILS_ENV=production -processes 1 -idle-timeout 60

I am not sure what will happen on Windows, but if you don’t start the
process together with Apache, the first request initializes this
procedure and maybe i forget about the process after some idle time. I
have no experience about that.

Maybe this is not much help.

Ciao,
Norman

Norman T.

http://blog.inlet-media.de

Jason A.on wrote:

Wondering: Does Apache shut down inactive FastCGI processes if it
doesn’t get any requests for a while? My app works fine if it’s being
used regularly, but it will respond very slowly to the first request
after an hour of zero traffic.

Interestingly, I’m experiencing exactly the same thing using
FastCgiExternalServer. The fcgi processes are kicked off by spawn-fcgi
and look quite happy sitting there. Apache2.0 is always slow to
acess the the first time after a lack of activity. As soon as that
first hit is over, it’s nice and fast, but when I head back to
developing locally for an hour or so, and then deploy again into
production (god bless you switchtower) I get the pause.

I’m guessing in my case it’s because even though the process is still
alive, the bulk of the app is not loaded until that first request
post-deploy…

Not sure if this can help shed any light :slight_smile:

A.

On Jan 12, 2006, at 6:44 AM, Alan wrote:

and look quite happy sitting there. Apache2.0 is always slow to

A.

I have seen this behavior before. It seems to me that when the

fcgi’s sit idle for too long the get pages out of memory. Then when
you hit the site after its been idle, the fcgi’s have to page back
into memory so hence the lag. The kludge that I use works great but
I’d be interested if there was another way. But this technique works
great in production for me.

Just add a cron job that uses curl or wget to grab a page thats not

cached(so it goes through rails) and send the output to /dev/null. If
you have the corn job do this once every 5 minutes your fcgi’s will
always be ‘awake’ . And one hit every 5 minutes is virtually no extra
load on the server. But by doing things this way, your site will
always be snappy no matter how long it has been since a user visited
the site.

Cheers-

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
[email protected]