我的mongodb非常简单:数据集/条目在3层上有大约30个属性。一个这样的条目有大约5000个字符。我有500k。 当我执行以下查询......Mongodb查询异常缓慢
db.images.find({ "featureData.cedd": { $exists: false}}).count()
...它是极其缓慢。它没有编入索引,但仍然...从我的MySQL经验来看,它不应该用20分钟执行一个这样的查询。
在执行时(直接在mongo终端上),CPU使用率为3%,仍然超过2G的可用内存。
谢谢你给我提示我可以做什么!
编辑:查询的解释()(不计数)给出:iostat的的
db.images.find({ "featureData.cedd": { $exists: false }}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 532537,
"nscannedObjects" : 532537,
"n" : 438,
"millis" : 1170403,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
输出:解释()的
Linux 3.2.0-58-generic (campartex) 03/25/2014 _x86_64_ (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
34.93 0.01 0.25 0.48 0.00 64.33
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 2.08 103.79 11.26 172805914 18749067
fd0 0.00 0.00 0.00 148 0
输出添加索引后:
db.images.find({ "featureData.cedd": { $exists: false }}).explain()
{
"cursor" : "BtreeCursor featureData.cedd_1",
"nscanned" : 438,
"nscannedObjects" : 438,
"n" : 438,
"millis" : 2,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : true,
"indexOnly" : false,
"indexBounds" : {
"featureData.cedd" : [
[
null,
null
]
]
}
}
'解释查询总是一个好的第一步 – shx2
顺便说一句,在编写诸如“计数mongo必须通过所有字符”之类的东西之前,请考虑一下,我们在这里谈论15分钟只有50万条记录。 。:) – Doidel
我只能找到一个“解释()”,没有描述。并且“解释”现在运行1分钟x/CPU和内存使用率相同低 – Doidel