I'm using mongodb for saving log data.

When I have to find something from log data, which could be over than 1,000,000 documents, all the process work properly but the issue is that memory usage doesn't get down even though the process has been finished.

When I enter 'top' command on the server that runs mongod process, it shows resource information like below screenshot.

Memory usage for the mongod process was less than 10%, but after using a lot of find() queries, it increased to 38.9% and never decreasing. What causes this kind of issue and what do I do to decrease the memory usage of mongod process except restarting? enter image description here

I didn't know that this question is not appropriate for stackoverflow site, but when I asked the same question in stackoverflow someone replied me like this. "Of course it doesn't, it's a database. They are meant to consume memory and hold on to it"

But what I did with my code was just using .find() query, nothing was added to database. Does it mean that only using find() query could have caused increasing of memory usage and not releasing it? I don't understand help me please


MongoDB use all memory, always! Reason why find increases memory usage (compare to fresh started machine) is that with every find, mongod will fill it's cache more to server clients better. It tries to keep active indexes and data in the memory, if possible.

  • Thanks for the reply. Then someday memory usage will face it's limit, how do you solve it? – yaboong Jun 5 '17 at 8:59
  • Then mongo starts pageFault:ing. It's not bad thing, it's just means that mongo must throw some information out of memory and read new data from disk to serve clients. Of course it's slower than serve data direct from memory. Especially, if client then asks that information what was just throw away.. It must be read back to memory (and before that throw something else out...) – JJussi Jun 5 '17 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.