MongoDB Database Profiler

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

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版本之后才有。包含查询操作执行数据的文档。只有查询操作才有这个文档。

要Linux上安装和部署MongoDB并创建数据库,可以按照以下步骤进行操作: 1. 首先,参考中的方法,创建一个mongodb文件夹,并将MongoDB的压缩包复制到该文件夹中。 2. 接下来,解压MongoDB压缩包并将文件移动到所需的位置。可以根据个人喜好选择移动到适当的目录。 3. 配置系统文件profile,可以根据需要进行设置,以确保MongoDB在系统启动时自动启动。 4. 创建一个文件夹并修改相关权限,以便MongoDB可以正常工作。 5. 编写MongoDB的启动配置文件,可以在配置文件中设置MongoDB的参数,例如端口号、日志路径等。 6. 在MongoDB的bin目录下,编写一个shell脚本,用于启动MongoDB服务。 7. 启动MongoDB服务,可以使用先前编写的shell脚本来启动MongoDB。 8. 测试MongoDB是否成功启动,可以使用命令行或MongoDB的客户端工具连接到MongoDB服务器,并执行一些基本的操作,例如插入数据或查询数据。 9. 创建数据库,可以使用命令行或MongoDB的客户端工具来创建新的数据库。 10. 参考中的说明,可以深入学习MongoDB的操作方法和补充说明。 请注意,上述步骤中的具体命令和操作可能会因系统版本和个人设置而有所不同。建议参考相关文档和教程,并根据实际情况进行操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Linux操作系统下的MongoDB使用手册](https://blog.csdn.net/weixin_43934075/article/details/124732807)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Linux 安装部署 MongoDB 并创建数据库](https://blog.csdn.net/weixin_41922349/article/details/107318069)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值