[MongoDB] – WiredTiger and Memory usage in containers

Understanding WiredTiger

The WiredTiger storage engine is the default storage engine which starting in MongoDB version 3.2. It uses MultiVersion Concurrency Control (MVCC) architecture, for write operations in order to allow multiple different modifications in the same document at the same time (concurrency).

Also, WiredTiger cache the information and create checkpoints which gives the ability to recover checkpoints anytime when it’s necessary, for example, if a MongoDB image deployed in a container fails it will be useful to recover the data that was not persistent. For OpenShift it will be useful to share the data between the pods and don’t lose the data in crash situations where the MongoDB pod will be killed and a new instance will be created automatically, in this way, this new instance will be able to recover the data between checkpoints. Also, WiredTiger can recover un-checkpointed data with its journal files. See the journal documentation for a further understanding.

Memory usage

By default in the 3.2 version, it will use 1Gi of memory or 60% of the available amount if it will upper than 1Gi according to its docs and this percentage of usage was changed for 50%  in the 3.4 released of MongoDB.

However, it is important to highlight that if WiredTiger cache size consumes all memory available of a container then memory issues will be faced and you must set storage.wiredTiger.engineConfig.cacheSizeGB and use –wiredTigerCacheSizeGB to add a value less than the amount of RAM available in the container.

For ​3.2​ version of MongoDB is required use as a workaround the property `configString:cache_size=${MONGODB_MAX_WIRED_TIGER_CACHE_SIZE}` for it accept values lower than 1Gi. For further information see the bug tracked in the MongoDB JIRA.  Following an example of it.

# storage Options - How and Where to store data
storage:
    # Directory for datafiles (defaults to /data/db/)
    dbPath: ${MONGODB_DATADIR}
    wiredTiger:
       engineConfig:
           configString: cache_size=${MONGODB_MAX_WIRED_TIGER_CACHE_SIZE}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s