Slow response from rails app


#1

I have a rails app that I am just starting to beta test with real people. I have a shared hosting account for now but I plan to upgrade to VPS as I get closer to live. I’m using passenger.

I am seeing long delays when I access my site - sometimes up to 10 seconds. Subsequent hits are always much faster. The rails production.log reports that requests take less than a second to process within rails so where are the other 9 seconds spent?

My best guess is that, because my traffic is so infrequent, my app gets switched out and each visitor has to wait while my app and/or rails is loaded from disk but I don’t know how to confirm that or address it.

Is there somewhere I can check to see what is happening for those other 9 seconds?

If my theory is correct, what can I do about it? If it’s not, any other theories? Would the response on VPS be better?

Thanks,

Kevin


#2

I’ve noticed a similar phenomenon with PHP. My guess is that the initial overhead is in creating a PHP process which stays active for some time (30 seconds? 1 minute? not sure, really) after the page has been served. Therefore subsequent requests are much faster if the process is still active. I’ve never seen a 9 second delay though. Probably more like 5-6.

However, I have noticed that DB queries have become very slow lately. I’ve seen some taking 10+ seconds even though they are very simple SELECT and JOIN queries. Retrying the query usually results in more normal speeds (0.02 seconds or so), but I’m guessing that MySQL does some query result caching?