MongoDB users: do you have a way to tell how much memory each collection is using? For the Wish Engineering team, the answer was "no," and that's why they developed MongoMem. MongoMem allows MongoDB developers to precisely locate collections in need of memory-use optimization, rather than searching for problems based on intuition. According to the Wish team's overview of MongoMem, the need was clear:
In our early days, we kept using a lot more memory than we thought we should be, but we were running blind when we tried to decide where the low-hanging fruit was to optimize. After plenty of frustrating optimizations that didn’t make much difference, we decided that we really needed better information, and MongoMem was born.
The Wish team's overview goes into detail on how MongoMem works - mincore calls and the collStats command do most of the work - what you can do with it, and even details some of the plans for MongoMem's future. Overall, though, it's a pretty straightforward little tool:
For each collection, it prints:
- Number of MB in memory
- Number of MB total
- Percentage of the collection that’s in memory
You can find MongoMem on GitHub (with the usage instructions repeated), so if you're looking for some insight on how to keep MongoDB from overdoing it on memory, this might be a useful tool for you.