user1944807
user1944807

Reputation: 41

mongodb memory usage is going high even if only insertions are made

I am using mongodb for only inserting documents. There are no indexes created for the collection I use. But I see that memory used by Mongodb is going high. Machine is having 20GB of RAM which is completely used. I would like to know the reason for this and is this normal?

Upvotes: 4

Views: 7252

Answers (1)

Asya Kamsky
Asya Kamsky

Reputation: 42352

There is an excellent discussion of how MongoDB uses storage and memory here:

http://docs.mongodb.org/manual/faq/storage/

Specifically to your case, Mongo memory maps the files that data and indexes live in (the ones inside of /data/db directory by default) which means that the files are mapped to OS's virtual address space and then whenever MongoDB accesses a page (any part of the file) that page will get pulled into RAM and it will stay there until all of RAM that's made available to mongod process by the OS is used (at that point least-recently-used pages will be swapped out of RAM).

You are inserting data and therefore you are writing to data files - those pages you are writing to need to be in RAM (mongo writes to files but since they are memory mapped it gets to interact with memory as if it's disk storage). If mongod is using 20GB+ of RAM that means your data plus your indexes (plus some overhead for other things) are 20GB or more.

Upvotes: 5

Related Questions