我在单个服务器上启动了mongodb实例,内存为96Gb。最大集合的CollStats:
"count" : 513025635,
"size" : 131860720528, //≈123Gb
"avgObjSize" : 257.02559781052656,
"storageSize" : 141246233632,
"numExtents" : 87,
"nindexes" : 1,
"lastExtentSize" : 2146426864,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 27554330048,
"indexSizes" : {
"_id_" : 27554330048 //≈25.7 Gb
}
我决定用我自己的类型为long的_id替换ObjectId。我很容易对索引大小感到困惑。它太长还是没问题?
最严重的问题是极慢的查询范围。
说明:
{
"cursor" : "BtreeCursor _id_",
"isMultiKey" : false,
"n" : 3935,
"nscannedObjects" : 3935,
"nscanned" : 3935,
"nscannedObjectsAllPlans" : 3935,
"nscannedAllPlans" : 3935,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 33,
"nChunkSkips" : 0,
"millis" : 32444,
"indexBounds" : {
"_id" : [
[
137607112986000,
137609013786000
]
]
},
"server" : "csdb:27017"
}
日志中的慢查询:
getmore csdb.archive query: { _id: { $gt: 1540584014914176, $lt: 1540584641314176 } }
cursorid:88959318045397 ntoreturn:0 keyUpdates:0 numYields: 2858 locks(micros) r:81292194
nreturned:21332 reslen:554652 415116ms
锁太多了?
工作集:
db.serverStatus({"workingSet":1}).workingSet
{
"note" : "thisIsAnEstimate",
"pagesInMemory" : 244491,
"computationTimeMicros" : 42233,
"overSeconds" : 3
}
这意味着缓存数据每3秒被驱逐一次,不是吗?
mongostat输出中的页面错误太多了:
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
*0 *0 *0 *0 0 1|0 0 162g 324g 64.7g 1719 csdb:0.0% 0 0|0 3|0 62b 2k 52 14:59:04
*0 *0 *0 *0 0 1|0 0 162g 324g 64.7g 1657 csdb:0.0% 0 0|0 3|0 62b 2k 52 14:59:05
*0 *0 *0 *0 0 1|0 0 162g 324g 64.7g 1743 csdb:0.0% 0 0|0 2|0 62b 2k 52 14:59:06
*0 2 *0 *0 0 1|0 0 162g 324g 64.7g 1878 csdb:0.0% 0 0|0 3|0 203b 99k 52 14:59:07
*0 1 *0 *0 2 1|0 0 162g 324g 64.7g 1629 csdb:0.0% 0 0|0 5|0 299b 120k 52 14:59:08
*0 2 *0 *0 1 1|0 0 162g 324g 64.7g 1733 csdb:0.0% 0 0|0 3|0 248b 995k 52 14:59:09
*0 1 *0 *0 2 1|0 0 162g 324g 64.8g 1694 csdb:0.0% 0 0|0 4|0 299b 547k 52 14:59:10
*0 *0 *0 *0 0 1|0 0 162g 324g 64.8g 1519 csdb:0.0% 0 0|0 7|0 62b 2k 52 14:59:11
*0 5 *0 *0 0 1|0 1 162g 324g 64.8g 1504 csdb:0.0% 0 0|0 6|0 203b 327k 52 14:59:12
*0 *0 *0 *0 1 1|0 0 162g 324g 64.8g 1744 csdb:0.0% 0 0|0 3|0 158b 5k 52 14:59:13
查询有什么问题?我是否以某种方式重新组织索引以获得更好的范围查询性能?