db.system.profile.find()
是分析 MongoDB 性能的关键工具,其返回的文档包含丰富的性能指标。下面是对各参数的详细解释和优化建议:
{"op": "query", // 操作类型(query/update/remove)"ns": "test.users", // 命名空间"command": { ... }, // 完整命令"keysExamined": 0, // 索引扫描数"docsExamined": 1000, // 文档扫描数"nreturned": 10, // 返回文档数"millis": 120, // 执行时间(ms)"planSummary": "COLLSCAN" // 执行计划
}
1、核心性能指标
参数 | 类型 | 说明 | 优化建议 |
---|---|---|---|
op | string | 操作类型:query (查询)update (更新)insert (插入)delete (删除)command (命令) | 识别高频操作类型,针对性优化 |
ns | string | 操作的命名空间 (格式: 数据库.集合 ) | 定位热点集合 |
millis | int | 操作执行时间(毫秒) | 重点关注 >100ms 的操作 |
ts | timestamp | 操作发生的时间戳 | 分析时间分布模式 |
2、查询执行分析
参数 | 类型 | 说明 | 优化建议 |
---|---|---|---|
planSummary | string | 查询计划摘要:COLLSCAN (全表扫描)IXSCAN (索引扫描)FETCH (文档获取)SORT |