mongo分析器profile

分析慢查询
1、db.setProfilingLevel(级别)

0 – 不开启
1 – 记录慢命令 (默认为>100ms)
2 – 记录所有命令

2、

{
    "op" : "command",
    "ns" : "wjdipw.car",
    "command" : {
        "aggregate" : "car",
        "pipeline" : [ 
            {
                "$lookup" : {
                    "from" : "inetuser",
                    "localField" : "applicant",
                    "foreignField" : "_id",
                    "as" : "inetuser"
                }
            }, 
            {
                "$addFields" : {
                    "inetuser" : {
                        "$arrayElemAt" : [ 
                            "$inetuser", 
                            0
                        ]
                    }
                }
            }, 
            {
                "$count" : "count"
            }
        ],
        "cursor" : {
            "batchSize" : 32
        },
        "allowDiskUse" : false,
        "$db" : "wjdipw",
        "$clusterTime" : {
            "clusterTime" : Timestamp(1619064272, 1),
            "signature" : {
                "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" },
                "keyId" : NumberLong(0)
            }
        },
        "lsid" : {
            "id" : UUID("a48fcac9-5438-4748-9265-57e80250a3fe")
        },
        "$readPreference" : {
            "mode" : "secondaryPreferred"
        }
    },
    "keysExamined" : 0,
    "docsExamined" : 10,
    "cursorExhausted" : true,
    "numYield" : 0,
    "nreturned" : 1,
    "queryHash" : "A300CFDE",
    "planCacheKey" : "A2B33459",
    "locks" : {
        "ReplicationStateTransition" : {
            "acquireCount" : {
                "w" : NumberLong(23)
            }
        },
        "Global" : {
            "acquireCount" : {
                "r" : NumberLong(23)
            }
        },
        "Database" : {
            "acquireCount" : {
                "r" : NumberLong(23)
            }
        },
        "Collection" : {
            "acquireCount" : {
                "r" : NumberLong(24)
            }
        },
        "Mutex" : {
            "acquireCount" : {
                "r" : NumberLong(23)
            }
        }
    },
    "flowControl" : {},
    "responseLength" : 243,
    "protocol" : "op_msg",
    "millis" : 2,
    "planSummary" : "COLLSCAN",
    "ts" : ISODate("2021-04-22T04:04:32.985Z"),
    "client" : "192.168.8.31",
    "allUsers" : [],
    "user" : ""
}

3、解读
system.profile.op
这一项主要包含如下几类

insert(插入)
query(查询)
update(更新)
remove(删除)
getmore (从游标中取数据)
command(比以上插入、查找、更新、删除的综合还多,还统计了别的命令)
代表了该慢日志的种类是什么,是查询、插入、更新、删除还是其他。

system.profile.ns
该项表明该慢日志是哪个库下的哪个集合所对应的慢日志。

system.profile.command
该项详细输出了慢日志的具体语句和行为

system.profile.keysExamined
该项表明为了找出最终结果MongoDB搜索了多少个key

system.profile.docsExamined
该项表明为了找出最终结果MongoDB搜索了多少个文档

system.profile.keyUpdates
该项表名有多少个index key在该操作中被更改,更改索引键也会有少量的性能消耗,因为数据库不单单要删除旧Key,还要插入新的Key到B-Tree索引中

system.profile.writeConflicts
写冲突发生的数量,例如update一个正在被别的update操作的文档

system.profile.numYield
为了让别的操作完成而屈服的次数,一般发生在需要访问的数据尚未被完全读取到内存中,MongoDB会优先完成在内存中的操作

system.profile.nreturned
该操作最终返回文档的数量

system.profile.responseLength
结果返回的大小,单位为bytes,该值如果过大,则需考虑limit()等方式减少输出结果

system.profile.millis
该操作从开始到结束耗时多少,单位为毫秒

system.profile.execStats
包含了一些该操作的统计信息,只有query类型的才会显示

system.profile.execStats.stage
包含了该操作的详细信息,例如是否用到索引

system.profile.ts
该操作执行时的时间

system.profile.client
哪个客户端发起的该操作,并显示出该客户端的ip或hostname

system.profile.allUsers
哪个认证用户执行的该操作

system.profile.user
是否认证用户执行该操作,如认证后使用其他用户操作,该项为空

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 关于Mongodb的全面总结 MongoDB的内部构造《MongoDB The Definitive Guide》...
    中v中阅读 32,126评论 2 89
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,473评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,075评论 6 342
  • mysql笔试+面试题100题分享 ​ 转载自:http://blog.51cto.com/wn2100/2049...
    98b8dc01512b阅读 3,517评论 0 0
  • 核心概念 字符串:所有字段串必须使用UTF-8编码 数字:bson指定了三种数据类型:double,int,lon...
    渡边Hok阅读 3,926评论 0 1