# Idle Apache+FastCGI sleeping?

**URL:** <https://www.ruby-forum.com/t/idle-apache-fastcgi-sleeping/52207>\
**Category:** Rails\
**Created:** [January 11, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/idle-apache-fastcgi-sleeping/52207 "2006-01-11T22:52:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_A.on](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@Jason\_A.on](https://www.ruby-forum.com/u/Jason_A.on)\
**Post date:** [January 11, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/idle-apache-fastcgi-sleeping/52207/1 "2006-01-11T22:52:12Z")

</div>

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](http://www.thenewjhp.com)

---

<div class="post-metadata">

**Author:** ![Jason\_A.on](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@Jason\_A.on](https://www.ruby-forum.com/u/Jason_A.on)\
**Post date:** [January 12, 2006, 8:33am UTC](https://www.ruby-forum.com/t/idle-apache-fastcgi-sleeping/52207/2 "2006-01-12T08:33:23Z")

</div>

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](http://blog.inlet-media.de)

---

<div class="post-metadata">

**Author:** ![Jason\_A.on](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@Jason\_A.on](https://www.ruby-forum.com/u/Jason_A.on)\
**Post date:** [January 12, 2006, 3:44pm UTC](https://www.ruby-forum.com/t/idle-apache-fastcgi-sleeping/52207/3 "2006-01-12T15:44:56Z")

</div>

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 🙂

A.

---

<div class="post-metadata">

**Author:** ![Jason\_A.on](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@Jason\_A.on](https://www.ruby-forum.com/u/Jason_A.on)\
**Post date:** [January 12, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/idle-apache-fastcgi-sleeping/52207/4 "2006-01-12T19:05:19Z")

</div>

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](http://yakimaherald.com)  
509-577-7732  
removed\_email\_address@domain.invalid
