软件下载吧文章资讯

分类分类

深入讲解MongoDB的慢日志查询(profile)

2024-02-14 10:20作者:下载吧

前言

说到MongoDB的慢日志分析,就不得不提到profile分析器,profile分析器将记录的慢日志写到system.profile集合下,这个集合是一个固定集合。我们可以通过对这个集合的查询,来了解当前的慢日志,进而对数据库进行优化。

整体环境

MongoDB 3.2.5

实战

Part1:输出示范

在查询system.profile的时候,我们能够观察到所有的操作,包括remove,update,find等等都会被记录到system.profile集合中,该集合中包含了诸多信息,如:

{
“op” : “query”,
“ns” : “test.c”,
“query” : {
“find” : “c”,
“filter” : {
“a” : 1
}
},
“keysExamined” : 2,
“docsExamined” : 2,
“cursorExhausted” : true,
“keyUpdates” : 0,
“writeConflicts” : 0,
“numYield” : 0,
“locks” : {
“Global” : {
“acquireCount” : {
“r” : NumberLong(2)
}
},
“Database” : {
“acquireCount” : {
“r” : NumberLong(1)
}
},
“Collection” : {
“acquireCount” : {
“r” : NumberLong(1)
}
}
},
“nreturned” : 2,
“responseLength” : 108,
“millis” : 0,
“execStats” : {
“stage” : “FETCH”,
“nReturned” : 2,
“executionTimeMillisEstimate” : 0,
“works” : 3,
“advanced” : 2,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“docsExamined” : 2,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 2,
“executionTimeMillisEstimate” : 0,
“works” : 3,
“advanced” : 2,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“invalidates” : 0,
“keyPattern” : {
“a” : 1
},
“indexName” : “a_1”,
“isMultiKey” : false,
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 1,
“direction” : “forward”,
“indexBounds” : {
“a” : [
“[1.0, 1.0]”
]
},
“keysExamined” : 2,
“dupsTested” : 0,
“dupsDropped” : 0,
“seenInvalidated” : 0
}
},
“ts” : ISODate(“2015-09-03T15:26:14.948Z”),
“client” : “127.0.0.1”,
“allUsers” : [ ],
“user” : “”}

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消