Morphia iterator for large result set

753 views
Skip to first unread message

sukan

unread,
Oct 23, 2012, 7:51:18 PM10/23/12
to mor...@googlegroups.com
I'm trying to iterate through 5 millions records collection by using find(query).iterator(). I have also set the batchSize of the query to 100. The iterator runs through 3 million records and crash out with OutOfMemoryError with following exception stack trace

java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.resize(HashMap.java:462)
at java.util.HashMap.addEntry(HashMap.java:755)
at java.util.HashMap.put(HashMap.java:385)
at com.google.code.morphia.mapping.cache.DefaultEntityCache.notifyExists(DefaultEntityCache.java:40)
at com.google.code.morphia.mapping.cache.DefaultEntityCache.putEntity(DefaultEntityCache.java:81)
at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:472)
at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267)
at com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:53)
at com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:48)

From looking into morphia source code I could see that the entity records are cached, and this cache keeps growing which is probably why the exception. I was wondering if there is any way to get a handle on the cache and flush it periodically

Ben McCann

unread,
Apr 11, 2013, 8:34:07 PM4/11/13
to mor...@googlegroups.com
Ditto. This stinks. What'd you do to fix it? I might submit a patch to the fork since 10gen has completely abandoned the original.

James Green

unread,
Apr 12, 2013, 4:30:03 AM4/12/13
to morphia
Nothing seems to use the flush() method:
Need to understand what problem that entity cache actually solves to move forwards I think. I'll have time later to look and try to follow-up.



--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

shypy

unread,
Nov 20, 2013, 9:05:49 AM11/20/13
to mor...@googlegroups.com
I'm running into this issue in version 0.105
Looking at a hexdump, the DefaultEntityCache.existenceMap of the MorphiaIterator is massive after iterating through 1 million instances. Is there a way to flush existenceMap?
Reply all
Reply to author
Forward
0 new messages