跟踪MongoDB的性能? [英] Track MongoDB performance?

查看:81
本文介绍了跟踪MongoDB的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以跟踪MongoDB中的查询"性能?专门测试索引或子文档?

Is there a way to track 'query' performance in MongoDB? Specially testing indexes or subdocuments?

在sql中,您可以运行查询,查看执行时间和其他分析指标.

In sql you can run queries, see execution time and other analytic metrics.

我有一个庞大的mongoDB集合,并且想尝试不同的变体和索引,不确定如何测试,所以很高兴看到找到一条记录花了多长时间.(我是MongoDB的新手).谢谢

I have a huge mongoDB collection and want to try different variations and indexes, not sure how to test it, would be nice to see how long did it take to find a record.. (I am new in MongoDB). Thanks

推荐答案

在这里您可能会熟悉两件事.

There are two things here that you'll likely be familiar with.

  1. 说明计划
  2. 慢日志

说明计划

以下是一些基本文档.运行说明就像db.foo.find(query).explain()一样简单. (请注意,这实际上是在运行查询,因此,如果您的查询很慢,也是如此)

Here are some basic docs on explain. Running explain is as simple as db.foo.find(query).explain(). (note that this actually runs the query, so if your query is slow this will be too)

要了解输出,您需要检查以下慢日志中的一些文档.您基本上可以获得有关扫描了多少索引",找到了多少索引"等的详细信息.与此类性能详细信息一样,解释确实取决于您.阅读上方和下方的文档,为您指明正确的方向.

To understand the output, you'll want to check some of the docs on the slow logs below. You're basically given details about "how much index was scanned", "how many are found", etc. As is the case with such performance details, interpretation is really up to you. Read the docs above and below to point you in the right direction.

慢速日志

默认情况下,慢速日志处于活动状态,阈值为100毫秒. 此处是指向分析的完整文档的链接.几个关键点可帮助您入门:

By default, slow logs are active with a threshold of 100ms. Here's a link to the full documentation on profiling. A couple of key points to get you started:

获取/设置配置文件:

db.setProfilingLevel(2); // 0 => none, 1 => slow, 2 => all
db.getProfilingLevel();

查看慢查询:

db.system.profile.find()

这篇关于跟踪MongoDB的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆