-1

I'm having a problem with virtual memory usage using MongoDB on a server. NOTE: I have only a local user account without root privs.

The server's VM limit (from ulimit -v) is 120MB.

With an empty database, MongoDB is reporting 100MB of virtual memory used.

> db.serverStatus().mem 
{
    "bits" : 32,
    "resident" : 23,
    "virtual" : 100,
    "supported" : true,
    "mapped" : 0
}

As soon as I try to create my first data entry (through db.addUser in the admin database), it's failing with an out of memory error.

done allocating datafile DBPATH/admin.0, size: 16MB,  took 0.244 secs

ERROR:   mmap() failed for DBPATH/ admin.0 len:16777216 errno:12 Cannot allocate memory

I understand that with a small VM limit and 32-bit mongodb, I'm not going to be able to create gigantic databases, but that's OK. I don't need gigantic databases.

What I can't understand is why it is using so much virtual memory out of the gate, and why it can't create a single 16MB database table.

I have read the accepted answer on this other question. It clarified how mongodb uses virtual memory, but it didn't help me to understand what's going wrong here.

Lynn
  • 121

2 Answers2

4

You need to provide adequate resources for your MongoDB server -- that means LOTS of RAM.
You are limiting it to virtually none, so you should not expect it to work unless you set more reasonable memory use restrictions.


You seem to be laboring under the mistaken assumption that 100MB is a large amount of memory.
It's not.

A simple shell (let's take plain old vanilla Bourne sh as an example) is nearly 10MB Virtual Size.
A more complicated shell (say the Bourne-Again Shell bash) is just under 25MB.
An Apache web server worker can have a VM size of 150MB or more.

A database engine, even a NoSQL one, that is only 100MB virtual size and communicates over the network is frankly a programming miracle. If you expect to be able to do anything with that miracle you're going to have to give it enough RAM to actually hold and work with data.

voretaq7
  • 80,749
1

The virtual memory usage will represent the entire size of the data files (including empty space), not just the data in the database. When you call mmap() on a file, it just maps that all into virtual memory - it does not care what's in the file.

If you have a low virtual memory limit, then that host is simply not going to be suitable for MongoDB beyond a very small data set. You will be helped by running with the smallfiles option, but only a little.

Working set and resident memory are a completely different thing to the virtual memory requirements for MongoDB. For virtual memory, you will need to have at least the total size of your data files available, and if you run with journaling (you should, but it's generally not possible with 32-bit) that requirement doubles. As a general statement you should have a host with unlimited virtual memory to run MongoDB, if there are limitations imposed it's probably going to cause you a lot of problems.

It's not part of what you are asking, but I would also generally not recommend using the 32-bit version of MongoDB for anything besides some basic testing.

Adam C
  • 5,262