Rails app lags after inactivity

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

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 [email protected] wrote:

problems.

Has anyone run into this before? Ideas?

  • Rabbit

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


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

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. :slight_smile:

  • Rabbit

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/

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” [email protected]
wrote:

and put it back in memory.

hop around with no problems.

Has anyone run into this before? Ideas?

  • Rabbit

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


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

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
[email protected]
509-577-7732

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

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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732

Sweet. Thanks for the work-around Ezra. :slight_smile: