• 关于profile集合


    profile集合是mongodb的慢操作日志
    > db.getProfilingStatus()
    { "was" : 0, "slowms" : 100, "sampleRate" : 1 }

    可以通过getProfilingStatus来查看当前profile设置

    profile分为3个级别

    0:表明profile是关闭的,mongodb不会记录任何操作
    1:配合slowms做预值,mongodb会记录所有超过slowms的操作
    2:mongodb会记录任何操作
    设置profile级别
    > db.setProfilingLevel(2)
    { "was" : 0, "slowms" : 100, "sampleRate" : 1, "ok" : 1 }
    得到profile级别
    > db.getProfilingLevel()
    2
    > db.system.profile.find().sort({$natural:-1}).limit(2)
    { "op" : "query", "ns" : "test.system.profile", "command" : { "find" : "system.profile", "filter" : { }, "limit" : 10, "singleBatch" : false, "sort" : { "$natural" : -1 }, "$db" : "test" }, "keysExamined" : 0, "docsExamined" : 10, "cursorExhausted" : true, "numYield" : 0, "nreturned" : 10, "locks" : { "Global" : { "acquireCount" : { "r" : NumberLong(1) } }, "Database" : { "acquireCount" : { "r" : NumberLong(1) } }, "Collection" : { "acquireCount" : { "r" : NumberLong(1) } } }, "responseLength" : 5140, "protocol" : "op_msg", "millis" : 0, "planSummary" : "COLLSCAN", "execStats" : { "stage" : "LIMIT", "nReturned" : 10, "executionTimeMillisEstimate" : 0, "works" : 12, "advanced" : 10, "needTime" : 1, "needYield" : 0, "saveState" : 0, "restoreState" : 0, "isEOF" : 1, "invalidates" : 0, "limitAmount" : 10, "inputStage" : { "stage" : "COLLSCAN", "nReturned" : 10, "executionTimeMillisEstimate" : 0, "works" : 11, "advanced" : 10, "needTime" : 1, "needYield" : 0, "saveState" : 0, "restoreState" : 0, "isEOF" : 0, "invalidates" : 0, "direction" : "backward", "docsExamined" : 10 } }, "ts" : ISODate("2018-08-11T23:37:03.517Z"), "client" : "127.0.0.1", "appName" : "MongoDB Shell", "allUsers" : [ ], "user" : "" }
    { "op" : "query", "ns" : "test.system.profile", "command" : { "find" : "system.profile", "filter" : { }, "$db" : "test" }, "cursorid" : 63845545503, "keysExamined" : 0, "docsExamined" : 101, "numYield" : 0, "nreturned" : 101, "locks" : { "Global" : { "acquireCount" : { "r" : NumberLong(1) } }, "Database" : { "acquireCount" : { "r" : NumberLong(1) } }, "Collection" : { "acquireCount" : { "r" : NumberLong(1) } } }, "responseLength" : 44741, "protocol" : "op_msg", "millis" : 0, "planSummary" : "COLLSCAN", "execStats" : { "stage" : "COLLSCAN", "nReturned" : 101, "executionTimeMillisEstimate" : 0, "works" : 102, "advanced" : 101, "needTime" : 1, "needYield" : 0, "saveState" : 1, "restoreState" : 0, "isEOF" : 0, "invalidates" : 0, "direction" : "forward", "docsExamined" : 101 }, "ts" : ISODate("2018-08-11T23:35:25.260Z"), "client" : "127.0.0.1", "appName" : "MongoDB Shell", "allUsers" : [ ], "user" : "" }
    可以看到操作记录被记录在system.profile集合中,$natural是自然排序,-1表示操作的越晚,排在越前面
    op:操作类型,当前是query
    ns:是查询的命令空间,命名格式是数据库名字+集合名字
    query:查询的字符串
    ...
    profile适合应用测试,或者刚上线的时候,数据量太多需要加索引,加大小,每次启动都会占用一些性能
  • 相关阅读:
    为什么解析 array_column不可用,
    Android经常使用的布局类整理(一)
    C++ Coding Standard
    Kd-Tree算法原理和开源实现代码
    2013年10月5日国庆上班前一天
    2013年10月5日
    2013年10月3日合肥归来
    国庆第二天参加室友婚礼
    国庆随笔
    2013第40周日国庆放假前一天晚上
  • 原文地址:https://www.cnblogs.com/wzndkj/p/9461934.html
Copyright © 2020-2023  润新知