I have a mongodb service in Docker and trying to config eviction
option for it like the following in the docker compose yaml file:
mongodb-geo:
image: mongo:5.0
hostname: geo-db
volumes:
- geo:/data/db
command: --wiredTigerCacheSizeGB 1 --setParameter wiredTigerEngineRuntimeConfig="eviction=(threads_min=6,threads_max=12)"
restart: always
deploy:
replicas: 1
resources:
limits:
cpus: '0.3'
restart_policy:
condition: any
without the --setParameter
, the service is working well. But, using that, the service will not run.
So, my question is how to set eviction
for the MongoDB in docker compose yaml file?
More Context
What I am doing here is based on the MongoDB documentation for setting parameters and this post.
The documentation page you are referring to explicitly says:
wiredTigerEngineRuntimeConfig
Available for mongod only.
Specify wiredTiger storage engine configuration options for a running mongod instance.
This parameter is only available at runtime. To set the parameter, use the setParameter command.
WARNING
Avoid modifying the wiredTigerEngineRuntimeConfig unless under the direction from MongoDB engineers as this setting has major implication across both WiredTiger and MongoDB.
Consider the following operation prototype:
db.adminCommand({ "setParameter": 1, "wiredTigerEngineRuntimeConfig": "<option>=<setting>,<option>=> <setting>" })
Not sure how it worked for Chris, but the error in the docker log is consistent with the documentation:
{"t":{"$date":"2024-06-27T10:44:10.403Z"},"s":"F", "c":"CONTROL", "id":20574, "ctx":"-","msg":"Error during global initialization","attr":{"error":{"code":2,"codeName":"BadValue","errmsg":"Unknown --setParameter 'wiredTigerEngineRuntimeConfig'"}}}
You can employ docker-entrypoint-initdb.d to run the admin command like this:
./init.d/eviction.js:
db.adminCommand({
"setParameter": 1,
"wiredTigerEngineRuntimeConfig": "eviction=(threads_min=6,threads_max=12)"
})
and then in docker-compose add the volume:
volumes:
- geo:/data/db
- ./init.d/:/docker-entrypoint-initdb.d/
Then in the logs you should see something like this:
{"t":{"$date":"2024-06-27T10:56:25.551+00:00"},"s":"I", "c":"STORAGE", "id":22376, "ctx":"conn2","msg":"Reconfiguring WiredTiger storage engine","attr":{"config":"eviction=(threads_min=6,threads_max=12)"}}
followed by
{"t":{"$date":"2024-06-27T10:56:25.554+00:00"},"s":"I", "c":"COMMAND", "id":23435, "ctx":"conn2","msg":"Successfully set parameter to new value","attr":{"parameterName":"wiredTigerEngineRuntimeConfig","newValue":""eviction=(threads_min=6,threads_max=12)"","oldValue":""""}}
The only thing is that the initdb.d is invoked only on fresh containers, and you may need to re-apply the command when you restart it.