如何理解为什么MongoDB有时长读?

时间:2016-04-06 07:54:48

标签: mongodb performance nosql

MongoDB版本v3.2.1

引擎:wiredTiger

例如,这是典型的快速查找查询:

{ 
    "op" : "query", 
    "ns" : "partkom.cross", 
    "query" : {
        "find" : "cross", 
        "filter" : {
            "part_id1" : NumberInt(2148967), 
            "maker_id1" : NumberInt(833)
        }, 
        "shardVersion" : [
            Timestamp(60, 0), 
            ObjectId("56f50db2ebc50fdfa98e50df")
        ]
    }, 
    "keysExamined" : NumberInt(20), 
    "docsExamined" : NumberInt(20), 
    "cursorExhausted" : true, 
    "keyUpdates" : NumberInt(0), 
    "writeConflicts" : NumberInt(0), 
    "numYield" : NumberInt(0), 
    "locks" : {
        "Global" : {
            "acquireCount" : {
                "r" : NumberLong(2)
            }
        }, 
        "Database" : {
            "acquireCount" : {
                "r" : NumberLong(1)
            }
        }, 
        "Collection" : {
            "acquireCount" : {
                "r" : NumberLong(1)
            }
        }
    }, 
    "nreturned" : NumberInt(20), 
    "responseLength" : NumberInt(1666), 
    "protocol" : "op_command", 
    "millis" : NumberInt(1), 
    "execStats" : {
        "stage" : "FETCH", 
        "nReturned" : NumberInt(20), 
        "executionTimeMillisEstimate" : NumberInt(0), 
        "works" : NumberInt(21), 
        "advanced" : NumberInt(20), 
        "needTime" : NumberInt(0), 
        "needYield" : NumberInt(0), 
        "saveState" : NumberInt(0), 
        "restoreState" : NumberInt(0), 
        "isEOF" : NumberInt(1), 
        "invalidates" : NumberInt(0), 
        "docsExamined" : NumberInt(20), 
        "alreadyHasObj" : NumberInt(0), 
        "inputStage" : {
            "stage" : "SHARDING_FILTER", 
            "nReturned" : NumberInt(20), 
            "executionTimeMillisEstimate" : NumberInt(0), 
            "works" : NumberInt(21), 
            "advanced" : NumberInt(20), 
            "needTime" : NumberInt(0), 
            "needYield" : NumberInt(0), 
            "saveState" : NumberInt(0), 
            "restoreState" : NumberInt(0), 
            "isEOF" : NumberInt(1), 
            "invalidates" : NumberInt(0), 
            "chunkSkips" : NumberInt(0), 
            "inputStage" : {
                "stage" : "IXSCAN", 
                "nReturned" : NumberInt(20), 
                "executionTimeMillisEstimate" : NumberInt(0), 
                "works" : NumberInt(21), 
                "advanced" : NumberInt(20), 
                "needTime" : NumberInt(0), 
                "needYield" : NumberInt(0), 
                "saveState" : NumberInt(0), 
                "restoreState" : NumberInt(0), 
                "isEOF" : NumberInt(1), 
                "invalidates" : NumberInt(0), 
                "keyPattern" : {
                    "maker_id1" : NumberInt(1), 
                    "part_id1" : NumberInt(1)
                }, 
                "indexName" : "maker_id1_1_part_id1_1", 
                "isMultiKey" : false, 
                "isUnique" : false, 
                "isSparse" : false, 
                "isPartial" : false, 
                "indexVersion" : NumberInt(1), 
                "direction" : "forward", 
                "indexBounds" : {
                    "maker_id1" : [
                        "[833, 833]"
                    ], 
                    "part_id1" : [
                        "[2148967, 2148967]"
                    ]
                }, 
                "keysExamined" : NumberInt(20), 
                "dupsTested" : NumberInt(0), 
                "dupsDropped" : NumberInt(0), 
                "seenInvalidated" : NumberInt(0)
            }
        }
    }, 
    "ts" : ISODate("2016-04-06T07:41:56.586+0000"), 
    "client" : "172.16.10.217", 
    "allUsers" : [

    ], 
    "user" : ""
}

但有时这个查询需要比平常更长的时间(超过100毫秒)。对我来说很长一段时间!

{ 
    "op" : "query", 
    "ns" : "partkom.cross", 
    "query" : {
        "find" : "cross", 
        "filter" : {
            "part_id1" : NumberInt(214251369), 
            "maker_id1" : NumberInt(839)
        }, 
        "shardVersion" : [
            Timestamp(60, 0), 
            ObjectId("56f50db2ebc50fdfa98e50df")
        ]
    }, 
    "keysExamined" : NumberInt(15), 
    "docsExamined" : NumberInt(15), 
    "cursorExhausted" : true, 
    "keyUpdates" : NumberInt(0), 
    "writeConflicts" : NumberInt(0), 
    "numYield" : NumberInt(3), 
    "locks" : {
        "Global" : {
            "acquireCount" : {
                "r" : NumberLong(8)
            }
        }, 
        "Database" : {
            "acquireCount" : {
                "r" : NumberLong(4)
            }
        }, 
        "Collection" : {
            "acquireCount" : {
                "r" : NumberLong(4)
            }
        }
    }, 
    "nreturned" : NumberInt(15), 
    "responseLength" : NumberInt(1286), 
    "protocol" : "op_command", 
    "millis" : NumberInt(145), 
    "execStats" : {
        "stage" : "FETCH", 
        "nReturned" : NumberInt(15), 
        "executionTimeMillisEstimate" : NumberInt(140), 
        "works" : NumberInt(16), 
        "advanced" : NumberInt(15), 
        "needTime" : NumberInt(0), 
        "needYield" : NumberInt(0), 
        "saveState" : NumberInt(3), 
        "restoreState" : NumberInt(3), 
        "isEOF" : NumberInt(1), 
        "invalidates" : NumberInt(0), 
        "docsExamined" : NumberInt(15), 
        "alreadyHasObj" : NumberInt(0), 
        "inputStage" : {
            "stage" : "SHARDING_FILTER", 
            "nReturned" : NumberInt(15), 
            "executionTimeMillisEstimate" : NumberInt(0), 
            "works" : NumberInt(16), 
            "advanced" : NumberInt(15), 
            "needTime" : NumberInt(0), 
            "needYield" : NumberInt(0), 
            "saveState" : NumberInt(3), 
            "restoreState" : NumberInt(3), 
            "isEOF" : NumberInt(1), 
            "invalidates" : NumberInt(0), 
            "chunkSkips" : NumberInt(0), 
            "inputStage" : {
                "stage" : "IXSCAN", 
                "nReturned" : NumberInt(15), 
                "executionTimeMillisEstimate" : NumberInt(0), 
                "works" : NumberInt(16), 
                "advanced" : NumberInt(15), 
                "needTime" : NumberInt(0), 
                "needYield" : NumberInt(0), 
                "saveState" : NumberInt(3), 
                "restoreState" : NumberInt(3), 
                "isEOF" : NumberInt(1), 
                "invalidates" : NumberInt(0), 
                "keyPattern" : {
                    "maker_id1" : NumberInt(1), 
                    "part_id1" : NumberInt(1)
                }, 
                "indexName" : "maker_id1_1_part_id1_1", 
                "isMultiKey" : false, 
                "isUnique" : false, 
                "isSparse" : false, 
                "isPartial" : false, 
                "indexVersion" : NumberInt(1), 
                "direction" : "forward", 
                "indexBounds" : {
                    "maker_id1" : [
                        "[839, 839]"
                    ], 
                    "part_id1" : [
                        "[214251369, 214251369]"
                    ]
                }, 
                "keysExamined" : NumberInt(15), 
                "dupsTested" : NumberInt(0), 
                "dupsDropped" : NumberInt(0), 
                "seenInvalidated" : NumberInt(0)
            }
        }
    }, 
    "ts" : ISODate("2016-04-06T07:27:20.514+0000"), 
    "client" : "172.16.10.217", 
    "allUsers" : [

    ], 
    "user" : ""
}

为什么在最后一个例子中估计太长? "executionTimeMillisEstimate" : NumberInt(140)

如何理解为什么它工作145ms? ("millis" : NumberInt(145)

内存中的所有索引。

0 个答案:

没有答案