adacosta/mongoid_rails_migrations

Possible to turn off identity_map to prevent memory leaks?

Closed this issue · 3 comments

Hi there,

Thanks for the awesome gem btw. It's been very helpful.

I'm wondering if there is a convenient way to turn off the identity_map during migrations? If identity_map is on, mongoid will not know when to clear it (since migrations aren't web requests) and the migration process will continue to use more and more memory as you iterate over large datasets.

It's the same problem described here: http://dev.mensfeld.pl/2011/09/ruby-mongoid-and-memory-leaks-identity-map-problem/

So far I've just been setting Mongoid.identity_map_enabled = false at the top of def self.up, but it's easy to forget. Thanks!

Hi Brian,

Thanks for bringing this to my attention. I wasn't aware of this issue.

In order to fully support everyone in the same capacity, it seems it might be best to not make any changes in mongoid_rails_migrations. My reasoning is as follows:

  1. There is a workaround, as you've noted.
  2. This could cause issues for current users in ways which we haven't considered.
  3. The original bug (memory leak) isn't caused by mongoid_rails_migrations.

With this in mind, would it be ok if I closed this issue and created a wiki page noting and linking to this issue you've opened?

Sure thing....those reasons make sense to me.

Actually now that I think about it, it might make sense to fix at the mongoid level. For example have it off by default except in web requests, or something along those lines.

Anyway, thanks for the help!