Avoid NoMemoryError during model reindex with ferret in ruby on rails
Avoid NoMemoryError during model reindex with ferret in ruby on rails
When Ferret is used and we want to rebuild index via console, sometime we get following error:
NoMemoryError (failed to allocate memory)
This problem mostly comes on shared server where we have limited memory space.
To get ride of this issue we have to make following test to ensure batch size of rebuilding index
# ruby script/console production
>> Resume.find(:first).nil?
=> false
>> Resume.find(:all, :limit => 10).nil?
=> false
>> Resume.find(:all, :limit => 100).nil?
=> false
>> Resume.find(:all, :limit => 500).nil?
eval):3:in `each_hash': failed to allocate memory (NoMemoryError)
i.e. it cannot have 500 records in memory same time and default index batch size in acts_as_ferret is 1000
Fortunately we can change batch size in acts_as_ferret configuration.
find "self.aaf_configuration" in RAILS_ROOT/vendor/plugins/acts_as_ferret/lib/act_methods.rb
you see something like:
self.aaf_configuration = {
:index_dir => "#{ActsAsFerret::index_dir}/#{self.name.underscore}",
:store_class_name => false,
:name => self.table_name,
:class_name => self.name,
:single_index => false,
:reindex_batch_size => 1000,
:ferret => {}, # Ferret config Hash
:ferret_fields => {} # list of indexed fields that will be filled later
}
Here you can change reindex_batch_size according to your need.
It should stop NoMemoryError.
- rajesh's blog
- Login to post comments


