查询某一个特定集合的性能数据
db.system.profile.
find
( { ns :
'mydb.test'
} ).pretty()
查询慢于5毫米的操作
db.system.profile.
find
( { millis : { $gt : 5 } } ).pretty()
db.system.profile.find( { ts:{$gt : new ISODate("2016-10-20T13:04:33.027Z"), $lt : new ISODate("2016-10-20T13:06:33.027Z") } } ).pretty()
db.system.profile.find( { ts:{$gt : new ISODate("2016-10-20T13:04:33.027Z"), $lt : new ISODate("2016-10-20T13:06:33.027Z") } },{user: 0} ).sort({millis: -1})
Change Size of system.profile Collection on a Secondary
更改Secondary的system.profile大小必须要停掉Secondary以单实例运行,然后执行以上步骤
system.profile 输出结果
{
"op" : "query",
"ns" : "test.system.profile",
"query" : {
"find" : "system.profile",
"filter" : {
}
},
"keysExamined" : 0,
"docsExamined" : 4,
"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" : 4,
"responseLength" : 3098,
"protocol" : "op_command",
"millis" : 0,
"execStats" : {
"stage" : "COLLSCAN",
"filter" : {
"$and" : [ ]
},
"nReturned" : 4,
"executionTimeMillisEstimate" : 0,
"works" : 6,
"advanced" : 4,
"needTime" : 1,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 4
},
"ts" : ISODate("2016-10-21T09:19:19.219Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
>
system.profile.op
操作类型,可能的值有insert,query,update,remove,getmore,command
system.profile.ns
操作涉及到的库名和集合名
system.profile.query
查询语句
system.profile.keysExamined
3.2.0版本之后才有,之前的版本叫做system.profile.nscanned
MongoDB扫描索引键值的数量
通常情况下,如果keysExamined的值远大于nretured的值,数据库会扫描很多索引键值来查找结果。可以考虑创建或者调整索引来改善查询性能。
system.profile.docsExamined
3.2.0版本之后才有,之前的版本叫做system.profile.nscannedObjects
MongoDB扫描集合中的文档数量
system.profile.ndeleted
删除文档数量
system.profile.ninserted
插入文档数量
system.profile.nMatched
update操作匹配查询条件的文档数量
system.profile.nModified
update操作修改的文档数量
system.profile.keyUpdates
更新操作更改的索引键值数量。更改一个索引键值会有一定的性能影响,因为数据必须要移除老的key并插入新的key到B-tree索引中
system.profile.writeConflicts
写操作过程中出现的冲突数量
system.profile.numYield
当前操作让步于其他操作的次数。通常,当一个操作需要访问的数据还没有完全读入到内存会让步于其他操作。这样可以允许其他数据已经加载到内存的操作先完成,同时MongoDB读入让步的操作的数据到内存。
system.profile.locks
锁类型和锁模式
The possible lock types are:
Lock Type | Description |
---|---|
Global | Represents global lock. |
MMAPV1Journal | Represents MMAPv1 storage engine specific lock to synchronize journal writes; for non-MMAPv1 storage engines, the mode for MMAPV1Journal is empty. |
Database | Represents database lock. |
Collection | Represents collection lock. |
Metadata | Represents metadata lock. |
oplog | Represents lock on the oplog. |
The possible locking modes for the lock types are as follows:
Lock Mode | Description |
---|---|
R | Represents Shared (S) lock. |
W | Represents Exclusive (X) lock. |
r | Represents Intent Shared (IS) lock. |
w | Represents Intent Exclusive (IX) lock. |
system.profile.nreturned
这个操作返回的文档数量
system.profile.responseLength
这个操作返回文档的长度,长度太大会影响性能。
system.profile.millis
操作从开始到结束的时间,毫秒
system.profile.execStats
3.0版本之后才有。包含查询操作执行数据的文档。只有查询操作才有这个文档。