MongoDB is running out of memory on a 96GB root server when adding a single index on a timestamp field for a 50GB collection.
Does MongoDB have any option to run a query or task in “safe-mode”, e.g. without cutting the memory too much? It seems to be very touchy and can be crashed, e.g. by running some find queries with $lte/$gt on a non-indexed timestamp field.
MongoDB does not use its own memory management. Instead it uses the OS’ LRU. The OS is paging documents so heavily because it has used the amount of memory allocated to
mongod, aka your working set is bigger than the amount of RAM you have spare for MongoDB as such MongoDB is swapping page faults for most of it not all of your data ( a good reference for paging: http://en.wikipedia.org/wiki/Paging ).I would strongly not recommend restricting MongoDB in this case since it will run even worse however, especially on Linux, you can actually use
ulimiton themongouser you are using to runmongod: http://docs.mongodb.org/manual/administration/ulimit/Not really.
Naturally this shouldn’t cause an OOM exception for MongoDB, it could indicate a memory leak somewhere: http://docs.mongodb.org/manual/administration/ulimit/