【问题标题】:How to measure the query run time in MongoDB如何测量 MongoDB 中的查询运行时间
【发布时间】:2018-04-12 16:14:24
【问题描述】:

我正在尝试测量 MongoDB 中的查询运行时间。

步骤: 我在 mongoDB 中设置分析并运行我的查询 当我确实显示个人资料时,我得到了以下输出。

db.blogpost.find({post:/.* NATO .*/i})

blogpost是集合名称,我在查询中搜索了“NATO”关键字。

输出:它提取了 20 条记录,运行查询得到执行结果后,我得到以下输出:

在输出中我可以看到 3 个时间值,哪一个类似于 MySQL 中的持续时间?

query   blogtrackernosql.blogpost **472ms** Wed Apr 11 2018 20:37:54  
command:{  
        "find" : "blogpost",  
        "filter" : {  
                "post" : /.* NATO .*/i  
        },  
        "$db" : "blogtrackernosql"  
} cursorid:99983342073 keysExamined:0 docsExamined:1122 numYield:19 locks:{  
        "Global" : {  
                "acquireCount" : {  
                        "r" : NumberLong(40)  
                }  
        },  
        "Database" : {  
                "acquireCount" : {  
                        "r" : NumberLong(20)  
                }  
        },  
        "Collection" : {  
                "acquireCount" : {  
                        "r" : NumberLong(20)  
                }  
        }  
} nreturned:101 responseLength:723471 protocol:op_msg planSummary:COLLSCAN  
 execStats:{  
        **"stage"** : "COLLSCAN",  
        "filter" : {  
                "post" : {  
                        "$regex" : ".* NATO .*",  
                        "$options" : "i"  
                }  
        }, 
        "nReturned" : 101,  
        **"executionTimeMillisEstimate" : 422**,  
        "works" : 1123,  
        "advanced" : 101,  
        "needTime" : 1022,  
        "needYield" : 0,  
        "saveState" : 20,  
        "restoreState" : 19,  
        "isEOF" : 0,  
        "invalidates" : 0,  
        "direction" : "forward",  
        "docsExamined" : 1122  
} client:127.0.0.1 appName:MongoDB Shell allUsers:[ ] user:  

【问题讨论】:

    标签: mongodb mongodb-query query-performance


    【解决方案1】:

    这...

    "executionTimeMillisEstimate" : 422
    

    ... 是 MongoDB 的 估计,该查询将花费多长时间在 MongoDB 服务器上执行

    这...

    query   blogtrackernosql.blogpost 472ms
    

    ...必须是端到端时间,包括一些客户端部分(例如,形成查询并将其发送到 MongoDB 服务器)加上从 MongoDB 服务器返回到客户端的数据传输时间。

    所以:

    • 472ms 是从开始到结束的总时间
    • 422ms 是 MongoDb 服务器中花费的时间

    注意:输出还告诉您 MongoDB 必须扫描整个集合 ("stage": "COLLSCAN") 才能执行此查询。 FWIW,它必须扫描集合的原因是您使用的是不区分大小写的$regex。根据the docs

    不区分大小写的正则表达式查询通常不能有效地使用索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 2014-10-21
      相关资源
      最近更新 更多