vm.swappiness
(建议设为10),减少交换空间使用。echo never > /proc/sys/vm/transparent_hugepage/enabled
设置。/etc/security/limits.conf
。/etc/mongod.conf
中设置storage.wiredTiger.engineConfig.cacheSizeGB
,建议为服务器内存的50%-70%。systemLog.logRotate
为reopen
或reindex
。commitIntervalMs
(默认100ms)和syncPeriodSecs
(默认10s),平衡性能与数据安全。net.maxIncomingConnections
和net.maxOutgoingConnections
以适应高并发。db.collection.createIndex()
。explain("executionStats")
分析查询计划,避免全表扫描。projection
)仅返回必要字段,减少数据传输。limit()
+skip()
),避免一次性返回大量数据。db.collection.dropIndex()
。mongostat
:实时监控数据库状态(如QPS、连接数)。mongotop
:跟踪集合级读写耗时。systemd
限制MongoDB内存使用,如systemctl set-property mongod MemoryLimit
。