MongoDb Java驱动程序迭代游标非常慢

时间:2014-10-26 11:45:09

标签: mongodb cursor iteration

首先,我用谷歌搜索并搜索了这个论坛,但没有找到我的问题的直接答案,所以我决定问一个新问题。

我有一个包含大约20k传感器的“传感器”系列。我的查询非常简单:

QueryBuilder qb = new QueryBuilder().and(
    new QueryBuilder().put("q1").lessThan(rb).get(),
    new QueryBuilder().put("q3").greaterThan(ra).get()
);
DBCursor cursor = sensorColl.find(qb.get());
begin = System.currentTimeMillis();
while (cursor.hasNext()) {
    cursor.next();
}
long totalSearchTime = System.currentTimeMillis()-begin;
logger.debug("totalSearchTime: {}", totalSearchTime);

显示totalSearchTime是316647ms!我多次重复此代码段,平均需要相似的时间才能完成。这是查询的explain():

{
"cursor" : "BtreeCursor q1_1_q3_-1",
"isMultiKey" : false,
"n" : 16905,
"nscannedObjects" : 16905,
"nscanned" : 16905,
"nscannedObjectsAllPlans" : 16905,
"nscannedAllPlans" : 16905,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 132,
"nChunkSkips" : 0,
"millis" : 102,
"indexBounds" : {
    "q1" : [ 
        [ 
            -Infinity, 
            30
        ]
    ],
    "q3" : [ 
        [ 
            Infinity, 
            10
        ]
    ]
},
"server" : "localhost:27017",
"filterSet" : false,
"stats" : {
    "type" : "FETCH",
    "works" : 16907,
    "yields" : 132,
    "unyields" : 132,
    "invalidates" : 0,
    "advanced" : 16905,
    "needTime" : 1,
    "needFetch" : 0,
    "isEOF" : 1,
    "alreadyHasObj" : 0,
    "forcedFetches" : 0,
    "matchTested" : 0,
    "children" : [ 
        {
            "type" : "IXSCAN",
            "works" : 16906,
            "yields" : 132,
            "unyields" : 132,
            "invalidates" : 0,
            "advanced" : 16905,
            "needTime" : 1,
            "needFetch" : 0,
            "isEOF" : 1,
            "keyPattern" : "{ q1: 1.0, q3: -1.0 }",
            "isMultiKey" : 0,
            "boundsVerbose" : "field #0['q1']: [-inf.0, 30.0), field #1['q3']: [inf.0, 10.0)",
            "yieldMovedCursor" : 0,
            "dupsTested" : 0,
            "dupsDropped" : 0,
            "seenInvalidated" : 0,
            "matchTested" : 0,
            "keysExamined" : 16905,
            "children" : []
        }
    ]
}

}

这是统计数据()

{
"ns" : "sensor_db.sensors",
"count" : 16999,
"size" : 272697744,
"avgObjSize" : 16041,
"storageSize" : 315080704,
"numExtents" : 15,
"nindexes" : 2,
"lastExtentSize" : 84451328,
"paddingFactor" : 1.006,
"systemFlags" : 0,
"userFlags" : 1,
"totalIndexSize" : 1888656,
"indexSizes" : {
    "_id_" : 981120,
    "q1_1_q3_-1" : 907536
},
"ok" : 1

}

我在我的测试系统(我的笔记本电脑)中使用Intel(R)Core(TM)2 Duo CPU T7100 @ 1.80GHz,800 MHz和1.5GB RAM运行我的应用程序(其中〜700MB在查询时是免费的跑了)。磁盘空间为58GB,因此很多。

我希望这些信息足以进行分析。非常感谢任何建议!

0 个答案:

没有答案