I have a Rails app that processes a large (millions) number of records in a mysql database. Once it starts working, its memory use quickly grows at a speed of 50MB per secon
I was able to figure this out myself. There are two places to change.
First, disable IdentityMap. In config/application.rb
config.active_record.identity_map = false
Second, use uncached to wrap up the loop
class MemoryTestController < ApplicationController
def go
ActiveRecord::Base.uncached do
Person.find_each do |person|
# whatever operation
end
end
end
end
Now my memory use is under control. Hope this helps other people.