【发布时间】:2014-11-26 16:25:38
【问题描述】:
我正在尝试分析聚合管道的性能,特别是检查是否使用了索引、扫描了多少对象等。
我正在将数据库设置为完整分析:
db.setProfilingLevel(2)
但是在 db 的 'system.profile' 集合中,在聚合命令的结果记录中,execStats 始终为空。
这是命令的完整结果:
{
"op" : "command",
"ns" : "mydb.$cmd",
"command" : {
"aggregate" : "mycolection",
"pipeline" : [{
"$match" : {
"date" : {
"$gte" : "2013-11-26"
}
}
}, {
"$sort" : {
"user_id" : 1
}
}, {
"$project" : {
"user_id" : 1,
"_id" : 0
}
}, {
"$group" : {
"_id" : "$user_id",
"agg_val" : {
"$sum" : 1
}
}
}],
"allowDiskUse" : true
},
"keyUpdates" : 0,
"numYield" : 16,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(3143653),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(140),
"w" : NumberLong(3)
}
},
"responseLength" : 4990,
"millis" : 3237,
"execStats" : { },
"ts" : ISODate("2014-11-26T16:20:59.576Z"),
"client" : "127.0.0.1",
"allUsers" : [],
"user" : ""
}
【问题讨论】:
-
使用
db.collection.aggregate(..., { "explain" : true })获取有关使用的索引、nscanned 等的信息。 -
我尝试将 {"explain" : true} 与聚合一起使用,但它似乎只是计算计划,并没有实际执行查询,因此我没有得到 nscanned 统计信息等。
标签: mongodb performance profiling aggregation-framework