For example when running MyModel.import(force: true) in a Rails console, I'm seeing the Ruby process climb to almost 2GB in memory usage.
I haven't tried to reproduce this yet to do memory analysis, but I do see that it defaults to processing batches of 1000 records at a time. If your model instances consume a lot of memory, you might try decreasing the batch size to see if this helps your memory usage. E.g.:
MyModel.import(force: true, batch_size: 100)
Also, roughly how many records are there?
There are only ~7000 records of MyModel but we are also indexing a relationship which causes us to touch ~430000 records.
I reduced the batch_size to 10 and it helped significantly, thanks!
Most helpful comment
There are only ~7000 records of
MyModelbut we are also indexing a relationship which causes us to touch ~430000 records.I reduced the
batch_sizeto10and it helped significantly, thanks!