views:

410

answers:

3

I have created two very simple heroku apps to test out the service, but it's often taking several seconds to load the page when I first visit them:

All I did was create a simple sinatra app and deploy it. I haven't done anything to mess with or test the heroku servers. What can I do to improve response time? It's very slow right now and I'm not sure where to start. The code for the projects are on github if that helps.

Thanks so much.

+6  A: 
  • If your application is unused for a while it gets unloaded (from the server memory).
  • On the first hit it gets loaded and stays loaded until some time passes without anyone accessing it.

This is done to save server resources. If no one uses your app why keep resources busy and not let someone who really needs use them ?
If your app has a lot of continous traffic it will never be unloaded.

  • You can cheat by having a cron somewhere send requests to a blank page in the app at some interval, so it won't get unloaded.
clyfe
It's done so that the server can have some free memory if other applications require it. Secondly, it's quite easy to overload a server with applications if they're always running. There's numerous reasons. Clyfe nails the simple version of it.
Ryan Bigg
is that in the docs somewhere? how long after no use does that happen? thanks for the answer, that makes things a lot clearer :).
viatropos
I think it's a passenger behaviour
shingara
The easiest way to fix this is to increase your dynos to 2.
chap
+3  A: 

You might also want to investigate the caching options you have on Heroku w/ Varnish and Memcached. These are persisted independent of the dynos.

For example, if you have an unchanging homepage, you can cache that for extended periods in Varnish by adding Cache-Control headers to the response. Then your users won't experience the load hit until they want to "do something" rather than when they arrive.

sevennineteen
A: 

I am having the same problem. I deployed a Rails 3 (1.9.2) app last night and it's slow. I know that 1.9.2/Rails 3 is in BETA on Heroku but the support ticket said it should be fine using some instructions they sent me.

I understand that the first request after a long time takes the longest. Makes sense. But simply loading pages that don't even connect to a DB taking 10 seconds sometimes is pretty bad.

Anyway, you might want to try what I'm going to do. That is profile my app and see how long it takes locally. If it's taking 400ms then something is wrong. But if I get 50ms locally and it still takes 10 seconds on Heroku then something is definitely wrong.

Obviously, caching helps but you only get 5MB for free and once again, with ONE person using the site, it shouldn't be that slow.

cbmeeks