Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my basic Heroku apps taking two seconds to load?

I 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:

  • Cropify - Basic Sinatra App (on github)
  • Textile2HTML - Even more basic Sinatra App (on github)

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.

like image 684
Lance Avatar asked Apr 09 '10 09:04

Lance


People also ask

How long does it take for Heroku to wake up?

A free Heroku web dyno will go to sleep if it does not receive any web traffic within a 30 minute period. When a sleeping dyno receives web traffic it will become active again, but there is a short delay as the application needs to be reloaded.

Why Heroku app is not working?

There are some errors which only occur when the app is rebooting so you will need to restart the app to see these log messages appear. For most apps, we also recommend enabling one of the free logging addons from https://elements.heroku.com/addons#logging to make sure that your historical log data is being saved.

Is Heroku free slow?

There's no actual speed difference between paid Heroku and free. As others have mentioned, your app will "spin down" after a period of inactivity on the free service, and this does not happen on any level of paid service.

How long does Heroku app take to go to sleep?

When Do Apps Sleep? When an app on Heroku has only one web dyno and that dyno doesn't receive any traffic in 1 hour, the dyno goes to sleep. When someone accesses the app, the dyno manager will automatically wake up the web dyno to run the web process type.


2 Answers

  • 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.

There is an official note about this.

like image 126
clyfe Avatar answered Oct 12 '22 16:10

clyfe


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.

like image 36
sevennineteen Avatar answered Oct 12 '22 18:10

sevennineteen