vm.swappiness
设为10),启用大页内存(transparent_hugepage=never
)。storage.wiredTiger.engineConfig.cacheSizeGB
),启用压缩(如blockCompressor: snappy
)。net.maxIncomingConnections
),关闭详细日志(systemLog.verbosity: 1
),启用慢查询日志(operationProfiling.mode: slowOp
,阈值设为100ms)。db.collection.reIndex()
重建索引,删除冗余索引(通过db.collection.getIndexes()
查看)。find({}, {field: 1}
)减少数据传输,避免全表扫描,利用explain("executionStats")
分析查询计划。skip()
和limit()
分页,批量插入/更新数据以减少网络开销。mongostat
、mongotop
或第三方工具(如Prometheus+Grafana)监控性能指标,定期分析慢查询日志。mongodump
),清理过期数据,更新MongoDB至最新版本以获取性能优化和安全补丁。