我有一个连接到三个分片集群的 mongos。我在这个 mongos 实例中有一些数据库和集合。除了一个有性能问题外,所有其他集合都工作正常。下面命令运行需要45分钟
db.orders.find().explain('executionStats')
此集合中的文档总数为111898400
. 每个分片集群都有关于30000000
文档。我知道我没有针对分片键运行此查询,但我只是想知道这是否是花费这么长时间的原因。我预计最多需要几分钟,但不会超过 45 分钟。
以下是上述命令的执行统计信息。我怎样才能更多地分析它以找出为什么需要这么长时间?
"executionStats" : {
"nReturned" : 111432926,
"executionTimeMillis" : 2727745,
"totalKeysExamined" : 0,
"totalDocsExamined" : 111899059,
"executionStages" : {
"stage" : "SHARD_MERGE",
"nReturned" : 111432926,
"executionTimeMillis" : 2727745,
"totalKeysExamined" : 0,
"totalDocsExamined" : 111899059,
"totalChildMillis" : NumberLong(6550367),
"shards" : [
{
"shardName" : "s0",
"executionSuccess" : true,
"executionStages" : {
"stage" : "SHARDING_FILTER",
"nReturned" : 36545358,
"executionTimeMillisEstimate" : 2723505,
"works" : 36613353,
"advanced" : 36545358,
"needTime" : 67994,
"needYield" : 0,
"saveState" : 321990,
"restoreState" : 321990,
"isEOF" : 1,
"invalidates" : 0,
"chunkSkips" : 67993,
"inputStage" : {
"stage" : "COLLSCAN",
"nReturned" : 36613351,
"executionTimeMillisEstimate" : 2689811,
"works" : 36613353,
"advanced" : 36613351,
"needTime" : 1,
"needYield" : 0,
"saveState" : 321990,
"restoreState" : 321990,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 36613351
}
}
},
{
"shardName" : "s1",
"executionSuccess" : true,
"executionStages" : {
"stage" : "SHARDING_FILTER",
"nReturned" : 36423091,
"executionTimeMillisEstimate" : 1647595,
"works" : 36423093,
"advanced" : 36423091,
"needTime" : 1,
"needYield" : 0,
"saveState" : 305586,
"restoreState" : 305586,
"isEOF" : 1,
"invalidates" : 0,
"chunkSkips" : 0,
"inputStage" : {
"stage" : "COLLSCAN",
"nReturned" : 36423091,
"executionTimeMillisEstimate" : 1614736,
"works" : 36423093,
"advanced" : 36423091,
"needTime" : 1,
"needYield" : 0,
"saveState" : 305586,
"restoreState" : 305586,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 36423091
}
}
},
{
"shardName" : "s2",
"executionSuccess" : true,
"executionStages" : {
"stage" : "SHARDING_FILTER",
"nReturned" : 38464477,
"executionTimeMillisEstimate" : 2166740,
"works" : 38862619,
"advanced" : 38464477,
"needTime" : 398141,
"needYield" : 0,
"saveState" : 331525,
"restoreState" : 331525,
"isEOF" : 1,
"invalidates" : 0,
"chunkSkips" : 398140,
"inputStage" : {
"stage" : "COLLSCAN",
"nReturned" : 38862617,
"executionTimeMillisEstimate" : 2128083,
"works" : 38862619,
"advanced" : 38862617,
"needTime" : 1,
"needYield" : 0,
"saveState" : 331525,
"restoreState" : 331525,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 38862617
}
}
}
]
}
},
好吧,收藏的规模说明了一切。查询从所有分片中检索所有文档的完整形状,通过网络发送它们,然后将它们合并为一个结果。
实际上,对于这个数量的记录,我认为 45 分钟对于全扫描来说并不算多。