Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB is using too much memory

I'm working with MongoDB on a 32bits CentOS VPS with 1GB of internal memory. It works fine most of the time, but every now and then it's memory usage spikes and crashes my server.

Is there a way to prevent this, for example, by limiting the memory and CPU that MongoDB daemon uses?

I was thinking of running the Mongo daemon with ionice and giving it a low priority, but I'm not sure if that would work.

Any help or pointers are welcome!

like image 686
Sander Mangel Avatar asked Feb 04 '12 16:02

Sander Mangel


2 Answers

It is not currently possible to limit amount of memory. MongoDB uses memory-mapped file mechanism to access data files. Therefore, amount of used memory is governed by the system. The more data you touch, the more RAM you need.

like image 58
Sergio Tulentsev Avatar answered Sep 24 '22 11:09

Sergio Tulentsev


I'm guessing you're also running everything else on that same server?

Really, the best way to run mongo is to put it on its own server, where things like apache, mysql, etc. won't jump up and interfere with the RAM it wants to use. I had the same problem myself--the server would go into swap and choke itself every once in a while, with heavy use.

You'd probably be better off with two 512MB servers which is hopefully comparable in price (one running mongo, and one running the rest). I also thought about trying to run a VM with mongo on it within the VPS, but that fell into the "too much effort" category, for me.

And yeah, as dcrosta says, use 64-bit, unless you want to limit your data size to under 2GB (and why would you want to do that?)

like image 23
Eve Freeman Avatar answered Sep 22 '22 11:09

Eve Freeman