My rails app is using too much memory:
Process running mem=701M(136.9%)
Error R14 (Memory quota exceeded)
Until I solve the problem, how can I increase the memory size on heroku?
Will adding more web dynos will help split the memory?
Thanks
Heroku memory limits free , hobby , and standard-1X dynos can use 512 MB of memory, while standard-2X dynos have access to 1 GB. performance-M and performance-L dynos provide 2.5 and 14 GB of memory. Memory use over these limits writes to disk at much slower speeds than direct RAM access.
Use jemalloc to reduce Rails memory usage On Heroku, you can add jemalloc using a buildpack. For my app, it resulted in ~20% memory usage decrease. Just make sure to test your app with jemalloc thoroughly on a staging environment before deploying it to production.
Heroku has a log-runtime-metrics feature to monitor the memory usage now. and the memory usage will be shown on the server log. Read Heroku log-runtime-metrics docs for more information.
I have the same issue with one of my clients. Sometimes digging into memory leaks can be a difficult task especially when the source of the leak could be in a third party code.
What I do is each few hours restart several dynos. I picked up non high traffic hours to do the restarts.
create a cron:
namespace :utils do
desc "Restart app by process and time table"
task :restart => :environment do
time_hash = {
1 => %w[web.1 web.2 web.3],
3 => %w[web.4 web.5 web.6],
5 => %w[web.7 web.8 web.9],
7 => %w[web.10 web.11 web.12],
16 => %w[web.13 web.14 web.1],
18 => %w[web.2 web.3 web.4],
20 => %w[web.5 web.6 web.7],
22 => %w[web.8 web.9 web.10],
0 => %w[web.11 web.12 web.13 web.14],
}
processes = time_hash[Time.now.hour]
processes.each {|process| restart_process(process)} if processes
end
def restart_process(name)
puts "restarting process #{name}:"
heroku = Heroku::Client.new(ENV['APP_USERNAME'], ENV['APP_PASSWORD'])
heroku.ps_restart(ENV['APP_NAME'], :ps => name)
end
end
Use the hourly scheduler (heroku addon) to run this cron.
You can't. Dynos have a 512M.B quotas, even if you get more dynos you will still hit the same wall. Fix your memory leaks.
Each dyno gets 512MB of memory to operate within. Most applications will fit comfortably within this allowance, and as a developer you need not worry about memory at all.
In some cases, your dyno may reach or exceed that 512MB amount. Typically this is because of a memory leak in your application, in which case you may wish to use a memory profiling tool such as Oink for Ruby or Heapy for Python to track down the leak and fix it.
Dynos that exceed 512MB of memory usage will display an R14 error in the logs, like this:
You have a hard limit of 512Mb of RAM to play with no exceptions. This memory is on a per dyno basis. Therefore you will not be able to deploy your application onto Heroku as it stands with it's substantial RAM usage.
I rarely see applications topping a couple of hundred Mb of RAM so you really need to look at the source of the problem.
With your RAM usage, even on a typical VPS you'd struggle to run more than a couple of processes at once.
From the docs, yeah. That should do it..
"Each dyno gets 512MB of memory to operate within."
http://devcenter.heroku.com/articles/dynos
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With