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.
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).
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.
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’.
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…
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.
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: