• 查看mongodb执行命令耗时


     

    1.开启日志,超过10毫秒的都记录
    db.setProfilingLevel( 1 , 10)

     

    2.执行命令
    db.metric.aggregate([{$group: {_id: '$month', totalcnt: {$sum: 1}}}])

     

    3.查看执行情况

    > db.system.profile.find().pretty()
    {
            "op" : "command",
            "ns" : "db_test.metric",
            "command" : {
                    "aggregate" : "metric",
                    "pipeline" : [
                            {
                                    "$group" : {
                                            "_id" : "$month",
                                            "totalcnt" : {
                                                    "$sum" : 1
                                            }
                                    }
                            }
                    ],
                    "cursor" : {
    
                    },
                    "lsid" : {
                            "id" : UUID("fda589d9-c981-4f93-9341-fca9980f77b3")
                    },
                    "$readPreference" : {
                            "mode" : "secondaryPreferred"
                    },
                    "$db" : "db_test"
            },
            "keysExamined" : 0,
            "docsExamined" : 1000000,
            "cursorExhausted" : true,
            "numYield" : 1026,
            "nreturned" : 1,
            "locks" : {
                    "ReplicationStateTransition" : {
                            "acquireCount" : {
                                    "w" : NumberLong(1058)
                            }
                    },
                    "Global" : {
                            "acquireCount" : {
                                    "r" : NumberLong(1058)
                            }
                    },
                    "Database" : {
                            "acquireCount" : {
                                    "r" : NumberLong(1057)
                            }
                    },
                    "Collection" : {
                            "acquireCount" : {
                                    "r" : NumberLong(1057)
                            }
                    },
                    "Mutex" : {
                            "acquireCount" : {
                                    "r" : NumberLong(31)
                            }
                    }
            },
            "flowControl" : {
    
            },
            "storage" : {
    
            },
            "responseLength" : 149,
            "protocol" : "op_msg",
            "millis" : 1732,
            "planSummary" : "COLLSCAN",
            "ts" : ISODate("2022-03-24T03:29:11.433Z"),
            "client" : "192.168.1.135",
            "appName" : "MongoDB Shell",
            "allUsers" : [ ],
            "user" : ""
    }

     

    这里执行1732毫秒

     

    4.关闭日志
    db.setProfilingLevel(0)

     

  • 相关阅读:
    java基础知识(一)- 数据类型
    Java基础知识-去重
    java基础知识-冒泡排序
    Java排序方法sort的使用详解
    Java面试题-字符串操作
    Map.Entry遍历Map
    Java中String的用法
    Java循环控制语句-switch
    API文档打开显示'已取消到该网页的导航'的解决方法
    CentOS6.5 安装snort
  • 原文地址:https://www.cnblogs.com/hxlasky/p/16048977.html
Copyright © 2020-2023  润新知