以下是一个Ubuntu MongoDB性能调优实战案例:
free -m
查看内存使用情况,根据实际情况增加内存。iostat
或vmstat
监控磁盘I/O。/etc/mongod.conf
文件,设置storage.wiredTiger.engineConfig.cacheSizeGB
为物理内存的50%-75%。net.maxIncomingConnections
和net.maxOutgoingConnections
。operationProfiling
参数设置。db.users.createIndex({username: 1})
。db.collection.getIndex()
查看索引,删除无用索引。mongostat
和mongotop
监控数据库性能,也可借助Prometheus和Grafana进行更详细监控。mongodump
和mongorestore
备份数据。