I've got Django app with mongoengine, which executes some aggregation-queries often enough.
The main problem is that mongod takes all the RAM and then crashes, so no LRU working, mongod just trying to get more and more memory.
My mongodb version is 3.2 and default engine is MMAPv1. As docs says, for caching MMAPv1 needs dataSize+indexSize amount of RAM. In my case that's about 370Mb (~290 for dataSize and ~80 for indexSize).
Here is my db.stats():
{
"db" : "random_db",
"collections" : 14,
"objects" : 155613,
"avgObjSize" : 1859.8720672437394,
"dataSize" : 289420272,
"storageSize" : 338821120,
"numExtents" : 32,
"indexes" : 22,
"indexSize" : 82512192,
"fileSize" : 1006632960,
"nsSizeMB" : 16,
"extentFreeList" : {
"num" : 25,
"totalSize" : 258314240
},
"dataFileVersion" : {
"major" : 4,
"minor" : 22
},
"ok" : 1
}
Actually I've got 1GB RAM and made swap-file for another 1GB. When my app executes first aggregation query (taking only 50 documents from collection), mongod RAM usage increasing to ~300Mb (when I start service it's about 50-100Mb), and till ~70 such queries been executed - all of my memory+swap ends and mongod crashes.
I've created all the indexes, that needs for aggregation's '$match', if needed, I can add some of them here.
So why ~4000 documents in cache taking more than 2GB of RAM, if my entire database takes only 370Mb and there is only 150k documents in db? I know I'm doing something wrong, the question is very simple, but still I can't find explanation at docs.
BTW, here is my db.serverStatus.mem:
{
"bits" : 64,
"resident" : 112,//this value growth when queries executed
"virtual" : 2523,
"supported" : true,
"mapped" : 1136,
"mappedWithJournal" : 2272
}
So, I guess, my mongod can't take more than 2523Mb for entire db in cache?