如果查询的执行时间超过 slowms 的值,则Performance Advisor会将其识别为慢速查询。默认下,此值为100 毫秒。您可以使用profile 命令或db.setProfilingLevel()mongosh 方法更改阈值。
例子
以下 profile 命令示例将阈值设置为 200 毫秒:
db.runCommand({ profile: 0, slowms: 200 })
如果您运行的是 MongoDB 3.6 或更高版本,则可以通过指定 sampleRate 参数,自定义性能优化顾问在日志中所使用慢查询的百分比。
例子
它会将慢速查询阈值设置为 100 毫秒的较低值,但也会将采样率设置为 10%。
db.runCommand({ profile: 0, slowms: 100, sampleRate: 0.1 })
注意
默认下,profile 的值为0 。 MongoDB建议保持此值不变,因为其他值可能会对数据库性能产生负面影响。要学习;了解详情,请参阅profile 命令。