!! Unexpected error while processing request: failed to allocate memory

落爺英雄遲暮 提交于 2019-12-04 06:53:08

问题


Please help me in solving this error.

I am getting this error while loading records from text files in to database using ruby scripts.

It just works fine if I use small number of records to load in to the database.But fails if there are large number of records.

CSV.foreach(fileName) do |line|
    completePath = line[0]                                                
    num_of_bps = line[1]

    completePath = cluster_path+ '/' + completePath
    inode = FileOrFolder.find_by_fullpath(completePath, :select=>"id") 

    metric_instance = MetricInstance.find(:first, :conditions=>["file_or_folder_id = ? AND dataset_id = ?", inode.id, dataset_id])
    add_entry(metric_instance.id, num_of_bps, num_of_bp_tests) 
end

def self.add_entry(metaid, num_of_bps, num_of_bp_tests)
    entry = Bp.new
    entry.metric_instance_id = metaid
    entry.num_of_bps = num_of_bps
    entry.num_of_bp_tests = num_of_bp_tests
    entry.save
    return entry
end  

回答1:


Try something like this:

File.open(fileName) do |csv|
  csv.each_line do |line|
    CSV.parse(line) do |values|
      # Here you can do your manipulation
    end
  end
end

This way is slower, but it should ensure you don't get out of memory.



来源:https://stackoverflow.com/questions/17109031/unexpected-error-while-processing-request-failed-to-allocate-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!