I have a Rails app hosted in Heroku. If I go the the site for the first time, it takes more than 10 seconds to start the app. After that, everything works fine and fast.
What should I do to boost first time loading? Should I add more Web Dynos, or more Worker Dynos, or do something with my configuration?
Thank you.
If you are on the free Heroku 1 dyno setup then the dyno will wind down after 1 hour of inactivity.
Should you pay for 1 or more extra dynos then none of you dynos will wind down and you will only ever face the bootup time when you push a new version.
You can choose to install the free New Relic add-on, and you can set this to ping your app every 2 minutes. This will stop it spinning down. http://addons.heroku.com/newrelic
Heroku unloads your app from memory if it is inactive for a while. See this answer for some suggestions: Why are my basic Heroku apps taking two seconds to load?
Related
I would like to use Rufus-Scheduler in order to send a mail daily.
I strictly followed the instructions given on GitHub here (the snippet, using Thin server, etc.); but nothnig happened (no mail sent) and I couldn't figured out the reason based on Heroku logs
my code
# config/initializers/scheduler.rb
require 'rufus-scheduler'
s = Rufus::Scheduler.singleton
# Here goes my mailing code (already tested and works well)
s.every '1d' do
Rails.logger.info "hello, it's #{Time.now}"
Rails.logger.flush
end
Is there some other points not mentionned on GitHub in order to make rufus-schedul work ? Many thanks
You can do this, but you have to understand how hobby dynos work. each free account is allocated hours like this.
Accounts are given a base of 550 hours each month in which your Free dynos can run. In addition to these base hours, accounts which verify with a credit card will receive an additional 450 hours of Free dyno quota.
Because rufus-scheduler runs as a thread in your ruby app process (this is why it starts running when you run rails console), as long as you have your server (I use puma) running, rufus scheduler will run just fine.
The downside is that if you run two processes in your server, say you run puma with 3-4 workers, you're going to have 3-4 of your schedulers running at the same time making it execute your scheduled events in triplicate/quadruplicate, so keep that in mind as well.
So the steps are simple
- make sure you have enough hours to run your dyno continuously all month
- use a service like pingdom, to ping your app every couple of minutes to keep the dyno active so that Heroku doesn't spin it down after 30 minutes of inactivity (it does that to free dynos)
- that should be all you need to do
Just remember that to run a dyno for a month you're going to need about 745 hours which your primary allocation covers (when you add a credit card). If for some reason you run out of hours (say you run two different apps on the account and use the method I describe below) then this could happen to you
A second notification will be sent when you reach 100% of your account quota, at which point your application’s dynos will be put to sleep for the remainder of that month. As a result, any apps using free dynos will not be accessible for the remainder of the month.
Seems like a lot of trouble to go to when you can just use the heroku scheduler to schedule rake tasks like everyone else does.
(Disclaimer, I'm not a Heroku expert, but I can google my way around and I can read documentation).
So, it's not your first Heroku - rufus-scheduler question... (Rails_using Rufus in order to schedule sending mails daily)
You say "in order to send a mail daily", so why don't you use the Heroku scheduler addon? https://devcenter.heroku.com/articles/scheduler It can schedule daily and even hourly (ironically, it may miss a schedule, so they recommend the below "custom clock process").
Do you realize that your dyno might be asleep when the time of the schedule comes? Heroku puts the dynos to "sleep" after a certain period of inactivity.
Heroku suggests to use a "custom clock process": https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes#custom-clock-processes
You have to get to know your target platform, Heroku, and adapt your system to it, with or without rufus-scheduler.
As a side-note, your previous post mentions Passenger, which is hard to tune to not kill rufus-scheduler's thread, but that wouldn't play a big role on Heroku where your dyno isn't supposed to live forever, rufus-scheduler can't outlive the dyno of its webapp, hence the "custom clock process" recommendation.
When loading my rails app in production (hosted on heroku) it takes up to 10 seconds to load. This only happens on the very first time the site is loaded. Any subsequent page views load normally. View at kurtiselliott.com
This is because Heroku will lazily spin up your dyno which essentially means that the first request will take ~10 seconds. If you leave your app idle for a little while Heroku will spin down your dyno.
See article for full explanation
https://devcenter.heroku.com/articles/dynos#dyno-sleeping
I've got Heroku deployment with my Rails 4 app and it's proving to be extremely slow. I'm not sure if my location has a factor as I'm based in Australia
I've got NewRelic addon and below is the problem that I'm seeing.
Category Segment % Time Avg calls Avg Time (ms)
View layouts/users Template 98.4 1.0 16,800
Based on this breakdown, I see that layout users is the problem for the performance (which is nearly 16.8 seconds!).
Is there a good way to profile this to find out exactly what functions are causing this problem and what are the best way to fix those?
Also another important thing to note is that when I go to map report it shows End User of 19.5 seconds which takes up a lot of time.
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. This causing delay for this first request.
Are you noticing similar behaviour?
It's a simple rails app. It just uses the postgresql database and it doesn't do any http calls except for newrelic monitoring. But once or twice a week I get an alert from newrelic that my app is down, and it lasts anywhere from 10 to 30 minutes. Is this normal?
The logs just show a bunch of H12 Request Timeout errors, but nothing else.
This is not a free account, I have two dynos running. This is not immediately after a deployment.
I've tried puma and unicorn, following all the guides out there for configuration. In the case of puma, the heroku router eventually starts timing out on requests. In the case of unicorn, unicorn itself starts timing out.
If you're running on a single dyno application the dyno is idled after a long period of inactivity. Its possible and likely that New Relic is reporting this as downtime. If it takes a long period for your application to start up then it may have already reported it as down. All applications that run 2 or more dynos are never idled.
I am currently developing a rails3.2 app and finding Heroku load times exceptionally slow. Can someone please tell me if this is what is to be expected with a paid server on Heroku?
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. The only other performance difference is that your app can only handle as many concurrent connections as there are dynos - so if two users connect to your free app at the same time, one has to wait for the other's request to finish (this is usually minimal and shouldn't bother anything until you start to get some traffic).
That having been said, you should also consider when your app is slow. If it's slow for the first request, and spry for requests after that, it's the spin-down issue and nothing to worry about. If all requests are slow, that's probably something that needs to be troubleshot in the app (though a paid Heroku account is probably still not the answer).
The free version idles after a period of inactivity. This is probably the slowness you are experiencing. The paid version does not idle.
I went through the same problem a couple of days ago and it seems like the best fix for this is to install the NewRelic addon to your heroku app. The NewRelic addon keeps on monitoring your web application (subsequently making periodic request to your app), ensuring that the dyno stays active. This effectively cancels out the idling issue.
One thing to note though, its probably best to install the addon only after you have finish a huge part of your development and are actively testing the app with beta users.
Also, note that in the paid version of heroku, the dyno never idles (as per their documentation). Hope this helps.