Reputation: 493
I gett OutOfMemoryError
while querying MongoDb with the 400k records.
I have a User collection with around 400k records. When I try to retrieve all the users (to dump it in elastic search), I get the OutOfMemoryError
error.
I have gone through this link and added jvm.memory=-Xms64m -Xmx1024m in the application.config, but still the same exception.
Here is my stack trace -
OutOfMemoryError occured : Java heap space
play.exceptions.JavaExecutionException: Java heap space
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.<init>(HashMap.java:209)
at java.util.LinkedHashMap.<init>(LinkedHashMap.java:181)
at org.bson.BasicBSONObject.<init>(BasicBSONObject.java:45)
at com.mongodb.BasicDBObject.<init>(BasicDBObject.java:42)
at com.mongodb.DefaultDBCallback._create(DefaultDBCallback.java:124)
at com.mongodb.DefaultDBCallback.create(DefaultDBCallback.java:87)
at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:68)
at com.mongodb.DefaultDBCallback.objectStart(DefaultDBCallback.java:63)
at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:63)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:206)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:197)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:207)
at org.bson.BasicBSONDecoder._decode(BasicBSONDecoder.java:80)
at org.bson.BasicBSONDecoder.decode(BasicBSONDecoder.java:58)
at com.mongodb.DefaultDBDecoder.decode(DefaultDBDecoder.java:56)
at com.mongodb.Response.<init>(Response.java:66)
at com.mongodb.DBPort.go(DBPort.java:128)
at com.mongodb.DBPort.call(DBPort.java:79)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:218)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:189)
at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:452)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:418)
at com.mongodb.DBCursor._hasNext(DBCursor.java:503)
at com.mongodb.DBCursor.hasNext(DBCursor.java:523)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1520)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1332)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1318)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:504)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:499)
at com.salambc.service.ProfileService.getUsers(ProfileService.java:895)
at controllers.Admin.index(Admin.java:56)
Upvotes: 4
Views: 3165
Reputation: 4500
Please check you application, you run out of memory because you have many big objects in memory. I met the same problem with that... Because all variable/function in Play! is static, so some of them cannot be released by GC.
Please check the way you use TemplateLoader, RenderArgs, Jobs... And try to reduce play pool and job pool (if you was setting on), best is 14 play pool for 4GB RAM (in my case).
Upvotes: 4
Reputation: 3833
You run out of memory because you load too much objects into memory.
Loading so much objects in a java memory isn't a good practice. You can't scale if a lot of users try to execute this use case.
Allowing more memory to your java process can solve your current bug but isn't a solution in the long term.
Try to think of another design where you can do some computation in your persistent store or load you data by small chuncks of data (100 or 1000) because loading chunk of data lead to predictible memory consumpltion
Upvotes: 1