How can I clear the mongoDB oplog?

Is it normal that MongoDB resident memory keeps growing?

  • I have one MongoDB(version 2.0.2) instance in production environment whose resident memory keeps growing and, in about 3 months, consumes up 24G physical RAM. The memory usage stats is as below: Currently, the MongoDB instance runs well and there is no latency spike is observed.  I'm wondering whether this is normal for MongoDB. Does MongoDB just try to consume all RAM to be more efficient? Is there way to limit RAM usage of MongoDB instance?

  • Answer:

    Does MongoDB just try to consume all RAM to be mos efficient? Most databases just try to consume all available RAM. However, in MongoDB's cases, it is using Memory-Mapped Files. So MongoDB effectively pretends that its entire data set is in RAM and it allows the operating system to "go to disk" when necessary. From a performance stand-point, MongoDB will generally start to get worse as more data lives outside of RAM, especially if that data is being accessed. Generally speaking, when the indexes exceed RAM the speed tends to drop off dramatically. So you will want to keep an eye on your index and data sizes. Is there way to limit RAM usage of MongoDB instance? Yes, this is theoretically possible. But you generally don't want to do that. You typically want MongoDB running on its own machine and basically owning all resources on that machine. If this is not the case, you'll want to consider the type of growth you are expecting, how you plan to clean up old data and how you plan to grow that system.

Gaëtan Voyer-Perrault at Quora Visit the source

Was this solution helpful to you?

Other answers

As already pointed out by @Gaëtan-Voyer-Perrault, like any other DB, mongo will use all the RAM it can. For best performance, you should always have your working set < RAM Size. More on this here http://stackoverflow.com/questions/6453584/what-does-it-mean-to-fit-working-set-into-ram-for-mongodb mongostat (http://docs.mongodb.org/manual/reference/mongostat/) is a pretty good tool which can tell you how many page faults you have along with the mapped size. Every insert will lead to RAM and disk consumption. Deleting might not be very handy as well because you would have to run repairdatabase which is a blocking operation. One effective way to limit RAM  is use a cappedcollection if it fits your use case. No need to worry about fragmentation and also about the working set (as long as your correctly estimate about the load and traffic growth for your app)

Abhinav Dhasmana

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.