Heroku迁移内存配额已超出

时间:2014-03-25 17:45:12

标签: ruby-on-rails postgresql heroku delayed-job rails-migrations

运行如下所示的迁移:

def up
  FileThumb.destroy_all # delete existing thumbnails
  File.update_all(thumbs_completed: false) # reset the process flags
  File.find_each do |file|
    file.delay(priority: 8).create_thumbs # delay thumbnail creation of each file.
  end
end

我的内存报价已超出

heroku/run.8084:  source=run.8084 dyno=heroku.3498745.1deecee6-afd0-466a-8020-38273704608c sample#load_avg_1m=0.00 sample#load_avg_5m=0.00 sample#load_avg_15m=0.02 
heroku/run.8084:  source=run.8084 dyno=heroku.3498745.1deecee6-afd0-466a-8020-38273704608c sample#memory_total=571.66MB sample#memory_rss=511.89MB sample#memory_cache=0.00MB sample#memory_swap=59.78MB sample#memory_pgpgin=1811564pages sample#memory_pgpgout=1680521pages 
heroku/run.8084:  Process running mem=571M(111.7%) 
heroku/run.8084:  Error R14 (Memory quota exceeded) 

1 个答案:

答案 0 :(得分:3)

这是因为在迁移中创建了太多对象,您必须更改查询,以便使用更少的内存。 您的问题的答案就在这个问题中:Heroku Error R14 (Memory quota exceeded): How do I solve this?

更具体地说,修复应该是......

def up
  FileThumb.destroy_all # delete existing thumbnails
  File.update_all(thumbs_completed: false) # reset the process flags
  File.find_in_batches(batch_size: 100) do |group|
    group.each {|file| file.delay(priority: 8).create_thumbs} # delay thumbnail creation of each file.
  end
end