# Rails app lags after inactivity

**URL:** <https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539>\
**Category:** Rails\
**Created:** [December 28, 2005, 2:59am UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539 "2005-12-28T02:59:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [December 28, 2005, 2:59am UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/1 "2005-12-28T02:59:17Z")

</div>

Hi all. I have two Rails applications. Each is on its own VPS hosted by  
Pipespring (excellent service btw).

My app runs lightning quick - AFTER the first load. If I visit my site  
after  
a period of inactivity (i.e. no visitors to my site), it takes up to 10  
seconds to load that first time. After that I can hop around with no  
problems.

Has anyone run into this before? Ideas?

- Rabbit

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [December 28, 2005, 3:53am UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/2 "2005-12-28T03:53:22Z")

</div>

Yeah, I’ve noticed the same thing. But it only happens

- for me anyway - in development mode. The first hit  
often times out. After that, it loads about as fast as  
production mode. Production mode is always fast.

I don’t know why this is. I’m using webbrick for  
development mode, and scgi for production mode (can’t  
remember if scgi in development mode suffers the same  
first-hit problem).

csn

— Rabbit [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> problems.
> 
> Has anyone run into this before? Ideas?
> 
> - Rabbit
> 
> > * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Yahoo! for Good - Make a difference this year.  
[http://brand.yahoo.com/cybergivingweek2005/](http://brand.yahoo.com/cybergivingweek2005/)

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [December 28, 2005, 4:26am UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/3 "2005-12-28T04:26:26Z")

</div>

Ah… Yeah the site it seems to happen to most IS in development. I have  
another site though that is in production mode and it still tends to lag  
if  
there’s been no activity on it for a while.

But, glad I’m not the only one experiencing this. If I find out what’s  
causing it I’ll post it here. 🙂

- Rabbit

* * *

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [December 28, 2005, 9:51am UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/4 "2005-12-28T09:51:15Z")

</div>

I experience this as well and I’m pretty sure it’s just swapping on  
the server.

If the server doesn’t have enough memory to hold all rails processes  
at once, then those not getting hit will be sent to disk. When you  
come along to request it, it has to recover that process from disc  
and put it back in memory.

If you have shell access on your hosting account you should be able  
to view this using top and ps and/or ‘free’ and ‘vmstat’.

Chris Nolan.ca  
[http://kekova.ca/](http://kekova.ca/)

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [December 28, 2005, 10:36am UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/5 "2005-12-28T10:36:30Z")

</div>

Here’s what ‘free’ shows on my box:

```
         total used free shared

```

buffers cached  
Mem: 1029868 1019924 9944 0  
442652 292420  
-/+ buffers/cache: 284852 745016  
Swap: 2048276 386416 1661860

So, with +/- buffers I should have about 750MB free.  
‘ps axu|grep ruby’ shows:

csn 25060 0.0 0.0 35800 4 pts/3 S  
Dec15 4:36 ruby  
/usr/local/lib/ruby/gems/1.8/gems/scgi\_rails-0.4.3/bin/scgi\_service  
config/scgi.yaml  
csn 18359 1.9 4.3 158584 44956 pts/3 D  
Dec21 183:17 ruby  
/usr/local/lib/ruby/gems/1.8/gems/scgi\_rails-0.4.3/bin/scgi\_service  
config/scgi.yaml  
csn 30260 0.0 1.5 28372 16208 pts/3 S  
Dec24 1:32 ruby ./script/server  
csn 26902 0.1 1.2 27248 13344 pts/5 S  
00:59 0:08 ruby ./script/server -p 3001

So the webbrick servers are using about 28K/15K  
VSZ/RSS each, and the one scgi has 158K/45K. The scgi  
servers do seem to grow rather large in size after a  
while.

I don’t think it’s due to swapping, but rather perhaps  
something timing out - like webbrick shuts down after  
a while and then has to startup. But still, my first  
hit after a while almost always results in a timeout  
(after about 30 seconds). I dunno…

csn

— “Chris Nolan.ca” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> and put it back in memory.
> 
> > hop around with no problems.
> > 
> > Has anyone run into this before? Ideas?
> > 
> > - Rabbit
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Yahoo! for Good - Make a difference this year.  
[http://brand.yahoo.com/cybergivingweek2005/](http://brand.yahoo.com/cybergivingweek2005/)

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [December 28, 2005, 4:40pm UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/6 "2005-12-28T16:40:54Z")

</div>

I have seen this same behavior on a few sites I made that don’t get  
much traffic. I’m not exactly sure why the processes ‘hibernate’ or  
whatever they do but the way I have fixed the problem is thus:

```
Create a cron job that curl's or wget's a page on your site every 5

```

minutes and sends the output to /dev/null . This will ‘exercise’ your  
site and keep the processes from having to startup or unswap or  
whatever they are doing.

Cheer-

-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [January 7, 2006, 11:47pm UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/7 "2006-01-07T23:47:07Z")

</div>

The lag during development mode has to do with the fact that your pages  
are  
being pulled from source every time you load them. You best option would  
be  
to put your app into production mode and work on caching content in  
order to  
increase speed.

-Kenny

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [January 8, 2006, 3:38am UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/8 "2006-01-08T03:38:39Z")

</div>

We are talking about production sites here that run on fcgi and don’t  
get traffic for large intervals of time. When these apps first get  
hit after a period of inactivity it takes a few seconds for the first  
page to load. Then after that the performance is great. The fcgi  
processes seem to get paged out of memory and take a few seconds to  
‘wake up’. So this method of using cron and wget just keeps the  
fcgi’s exercised and in memory instead of paged out to disk.

Cheers-  
-Ezra

On Jan 7, 2006, at 2:45 PM, Kenneth Parnell wrote:

> every 5  
> 509-577-7732
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [January 7, 2006, 11:16pm UTC](https://www.ruby-forum.com/t/rails-app-lags-after-inactivity/78539/9 "2006-01-07T23:16:58Z")

</div>

Sweet. Thanks for the work-around Ezra. 🙂

* * *
