Reputation: 4406
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
Upvotes: 11
Views: 12858
Reputation: 351
Heroku updated their API , so the comments above no longer work. I did a simpler spin off on the comments above ( in file : #{Rails.root}/lib/tasks/schedualer.rake) :
class HerokuMaintenance
def self.get_web_and_workers(get_ps_array)
output = []
get_ps_array.each do |i|
type = fetch('process',nil)
if type.match(/^worker\.\d+$/) or type.match(/^web\.\d+$/)
output << type
end
end
return output
end
#########################################################################
def self.restart_all
heroku_client.post_ps_restart(ENV['APP_NAME'])
end
#########################################################################
def self.get_ps_array(heroku_client)
heroku_client.get_ps(ENV['APP_NAME']).body
end
#########################################################################
def self.heroku_client
Heroku::API.new( :username => ENV['APP_USERNAME'] , :password => ENV['APP_PASSWORD'])
end
#########################################################################
desc "Restart app workers/web"
task :my_restart => :environment do
HerokuMaintenance.restart_all
end
Following the instructions in https://devcenter.heroku.com/articles/scheduler
1. heroku addons:create scheduler:standard
2. heroku run rake my_restart
3. heroku addons:open scheduler (I set it to run every hour due to some annoying memory issues I haven't solved yet).
Upvotes: 0
Reputation: 1305
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.
Upvotes: 8
Reputation: 22238
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.
Upvotes: 4
Reputation: 9835
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:
Upvotes: 6
Reputation: 734
From the docs, yeah. That should do it..
"Each dyno gets 512MB of memory to operate within."
http://devcenter.heroku.com/articles/dynos
Upvotes: 2