Pocket Theories
Dr. Katkam Nitin Reddy

MongoDB

TuneD

Updated: January 1, 2025


 # In /etc/tuned/mongodb/tuned.conf 

[main] 
summary=Optimize for MongoDB wiredTiger Performance 

[cpu] 
force_latency=1 
governor=performance 
energy_perf_bias=performance 
min_perf_pct=100 

[vm] 
#transparent_hugepages=always  # For MongoDB 8 and higher 
#transparent_hugepage.defrag=defer+madvise  # For MongoDB 8 and higher 
transparent_hugepages=never  # For MongoDB 7 and older 

[disk] 
readahead=8 

[sysctl] 
kernel.sched_min_granularity_ns=10000000 
vm.dirty_ratio=10 
vm.dirty_background_ratio=3 
vm.swappiness=1 
kernel.sched_migration_cost_ns=5000000 
net.ipv4.tcp_keepalive_time=120 
vm.zone_reclaim_mode=0 
kernel.pid_max=65536 
fs.file-max=98000 
kernel.threads-max=64000 
vm.max_map_count=131060 

# tuned-adm profile mongodb  # To activate the profile 
# Check with: tuned-adm active

For MongoDB 8, use the SystemD unit file (for setting khugepaged.max_ptes_none to 0) from:
https://www.mongodb.com/docs/manual/administration/tcmalloc-performance/#create-a-service-file (Note: For the SystemD unit file from the above link, use the "before" service name as "mongodb-mms-automation-agent.service")
	  

Ops Manager Version Manifest Update Script


#!/usr/bin/env bash
# Generate these global API keys in Ops Manager
PUBLICKEY=xxxxxxxx
PRIVATEKEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

OM_VERSION=7.0OM_URL='http://om_hostname:8080/api/public/v1.0/versionManifest'

# This line downloads the version manifest from the Internet
curl -OL https://opsmanager.mongodb.com/static/version_manifest/${OM_VERSION}.json?dummyQueryString=1 # You can instead make the file available on the filesystem (Eg. 7.0.json) and comment out the above line

curl --user "${PUBLICKEY}:${PRIVATEKEY}" --digest \
     --header "Accept: application/json" \
     --header "Content-Type: application/json" \
     --include \
     --request PUT "${OM_URL}" \
     --data "@${OM_VERSION}.json"

# This displays the manifest's date-time
UPDATED_ON=$(jq '.updated' ${OM_VERSION}.json )
UPDATED_ON_SEC=$(($UPDATED_ON / 1000))
date -d "@${UPDATED_ON_SEC}"
    

LogRotateD


In /etc/logrotate.d/mongod:
/var/log/mongodb/mongod.log {
   daily
   rotate 30
   dateext
   compress
   missingok
   notifempty
   sharedscripts
   create 640 mongodb mongodb
   postrotate
       killall -SIGUSR1 mongod
   endscript
}

In /etc/mongod.conf:
systemLog:
 destination: file
 logAppend: true
 logRotate: reopen
 path: /log/mongod.log