Elasticsearch-rails: Is it possible to reduce Ruby memory usage when running an `import`

Created on 6 Dec 2017  路  2Comments  路  Source: elastic/elasticsearch-rails

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.

Most helpful comment

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!

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings