Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any option to limit mongodb memory usage?

Tags:

mongodb

I am using Mongo-DBv1.8.1. My server memory is 4GB but Mongo-DB is utilizing more than 3GB. Is there memory limitation option in Mongo-DB?.

like image 400
kumar_88 Avatar asked Jul 28 '11 15:07

kumar_88


People also ask

How do I limit memory in MongoDB?

If you are running MongoDB 3.2 or later version, you can limit the wiredTiger cache as mentioned above. ... # Where and how to store data. storage: dbPath: /var/lib/mongodb journal: enabled: true wiredTiger: engineConfig: cacheSizeGB: 1 ...

Does MongoDB use a lot of memory?

The MongoDB statefulset has in production cluster 16 GB as memory limit, but is consuming more, 11 GB, and 20 GB in pre-production (Usually consuming 6-7 GB, which is OK).

What are limitations of MongoDB?

The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API.

What is in memory in MongoDB?

What is an in-memory database? An in-memory database is a data storage software that holds all of its data in the memory of the host. The main difference between a traditional database and an in-memory database relies upon where the data is stored.


2 Answers

If you are running MongoDB 3.2 or later version, you can limit the wiredTiger cache as mentioned above.

In /etc/mongod.conf add the wiredTiger part

... # Where and how to store data. storage:   dbPath: /var/lib/mongodb   journal:     enabled: true   wiredTiger:     engineConfig:         cacheSizeGB: 1 ... 

This will limit the cache size to 1GB, more info in Doc

This solved the issue for me, running ubuntu 16.04 and mongoDB 3.2

PS: After changing the config, restart the mongo daemon.

$ sudo service mongod restart  # check the status $ sudo service mongod status 
like image 178
mikkun Avatar answered Oct 09 '22 23:10

mikkun


Starting in 3.2, MongoDB uses the WiredTiger as the default storage engine. Previous versions used the MMAPv1 as the default storage engine.

  • With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.
  • In MongoDB 3.2, the WiredTiger internal cache, by default, will use the larger of either: 60% of RAM minus 1 GB, or 1 GB.
  • For systems with up to 10 GB of RAM, the new default setting is less than or equal to the 3.0 default setting (For MongoDB 3.0, the WiredTiger internal cache uses either 1 GB or half of the installed physical RAM, whichever is larger). For systems with more than 10 GB of RAM, the new default setting is greater than the 3.0 setting.

to limit the wiredTriggered Cache Add following line to .config file :

wiredTigerCacheSizeGB = 1

like image 22
Rajniprabha Avatar answered Oct 09 '22 23:10

Rajniprabha