How do i calculate WiredTiger cache size in a docker container?

4/2/2020

We run MongoDB mongod processes inside Docker containers in Kubernetes with clear memory limits.

I am trying to configure the mongod processes correctly for the imposed memory limits.

These are the information I could collect from the docs:

This information is a little unclear.

Do I leave the default values of the WiredTiger cache size or do I set it to "a value less than the amount of RAM available in the container"? How much lower should that value be? (a higher value than the default would also contradict the advice to not increase it above the default value)

-- Immanuel
docker
kubernetes
mongodb

1 Answer

4/2/2020

The default is to allow the WiredTiger cache to use slightly less than half of the total RAM on the system.

The process normally determines the total RAM automatically by querying the underlying operating system.

In the case of a Docker container which has been allocated 16GB of RAM but is running on a host machine that has 128GB RAM, the system call will report 128GB. The default in this case would be 63GB, which obviously would cause a problem.

In general:

  • Use the default in situations where the system call reports the true memory available in the environment. This includes bare metal, most VMs, cloud providers, etc.
  • In containers where the amount of memory reported by the system call does not reflect the total amount available to the container, manually make the calculation for what the default would have been if it did, and use that value instead.
-- Joe
Source: StackOverflow