free -m
查看内存使用情况,建议将WiredTiger缓存设为系统内存的50%-70%。/etc/mongod.conf
中storage.wiredTiger.engineConfig.cacheSizeGB
参数,合理分配内存。operationProfiling
中设置mode: slowOp
,监控慢查询。net.maxIncomingConnections
和net.maxOutgoingConnections
以适应高并发。db.collection.createIndex({ field: 1 })
。limit()
和skip()
进行分页,避免一次性返回大量数据。mongostat
、mongotop
或第三方工具(Prometheus+Grafana)监控性能。mongodump
和mongorestore
定期备份数据。