MongoDB Database Profiler

本文介绍如何使用MongoDB系统配置文件system.profile进行性能查询,包括查询特定集合的性能数据、慢于设定时间的操作及按时间范围筛选记录的方法。此外,还详细解释了system.profile输出字段的含义及其对性能的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查询某一个特定集合的性能数据

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 TypeDescription
GlobalRepresents global lock.
MMAPV1JournalRepresents MMAPv1 storage engine specific lock to synchronize journal writes; for non-MMAPv1 storage engines, the mode for MMAPV1Journal is empty.
DatabaseRepresents database lock.
CollectionRepresents collection lock.
MetadataRepresents metadata lock.
oplogRepresents lock on the oplog.



The possible locking modes for the lock types are as follows:

Lock ModeDescription
RRepresents Shared (S) lock.
WRepresents Exclusive (X) lock.
rRepresents Intent Shared (IS) lock.
wRepresents Intent Exclusive (IX) lock.


system.profile.nreturned  

  这个操作返回的文档数量


system.profile.responseLength

  这个操作返回文档的长度,长度太大会影响性能。


system.profile.millis

  操作从开始到结束的时间,毫秒



system.profile.execStats

  3.0版本之后才有。包含查询操作执行数据的文档。只有查询操作才有这个文档。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值