I am running a Rails 4 app on Heroku, with Puma server. I am using only one basic web dyno (no worker), with 512MB ram.
Recently, I have been facing a lot of R14 errors (Memory Quota Exceeded), my server crashed three times yesterday.
Here's my Puma config file :
workers Integer(ENV['WEB_CONCURRENCY'] || 0)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
I have few time-consuming tasks being performed each day on my server, I think they are the reason why I am getting these R14 errors and server crashes :
rake tasks being performed with Heroku Scheduler
imports of 10 photos (size max : 10 x 3MB) when creating / updating a model named Thing
exports of logs from my database, that can contain up to 6k rows
Here are my questions :
Will putting these time-consuming tasks on a new worker dyno help me avoid R14 errors / server crashes ? If yes, do you recommend using delayed_job_active_record gem or resque gem?
Do you think my Puma config file is ok ?
I can't figure out how to put rake tasks performed by Heroku Scheduler on a worker dyno. Any idea ?
Thanks a lot for your help !
I have no personal experience with setting up Heroku worker dynos, but as for your question #2 the file should be fine as long as you are running Rails 4.1 or newer, otherwise the config should match the recommendation in this link: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot.
In a recent attempt to upgrade my app to Rails 4.2, memory consumption raised significantly and R14 errors became much more frequent. So I downgraded back to Rails 4.1 (Ruby version is 2.2.2). Maybe that's something you could give a try.
Also, if you haven't done so, I recommend you installing the New Relic add-on and taking a look at the per-instance memory consumption at the "Monitoring/Instances" link.