source code bean

26 May, 2012

Limiting MongoDB memory usage on Windows 2008 Server

Posted by: Peter In: Windows Server

By default MongoDB tries to memory map as much as possible of the database file. Given a fairly big database, this will consume all your memory. If MongoDB is running on a dedicated server this is totally fine, but when running on a shared server this will cause unnecessary swapping for your other applications. At this point you want to limit the max amount of memory MongoDB can use. On Linux I have not found a way on how to do this (if you know a way please let me know!), but on Windows Server it is possible to limit it using WSRM.

WSRM allows greater control over the CPU and Memory available to a process and is an additional feature shipped with Windows Server that can be installed from the server manager under “Features Summary”:

Once installed we need to create a new resource allocation policy from the manager:

and give it some name:

Now we need to select processes to match with the policy:

We will select process from the list of registered services:

Here we find MongoDB:

Click OK a few times to exit the process selection. On the memory tab we can limit the memory for this resource allocation policy:

The final step is to make the policy active. To do this, go to the top level page in the manager and click the “Selected Policy” link. In here you can set the active policy:

That’s it! Now MongoDB will not consume more than 500MB of memory.



No Responses to "Limiting MongoDB memory usage on Windows 2008 Server"

Comment Form

Adwords

About

Welcome to source code bean! On this site I post stuff that I encounter in my job and spare time. The content is mostly related to .NET development, but my interest in techonology is very broad, so often you will find posts on totally different subjects!