简体   繁体   English

跟踪 MongoDB 性能?

[英]Track MongoDB performance?

Is there a way to track 'query' performance in MongoDB?有没有办法在 MongoDB 中跟踪“查询”性能? Specially testing indexes or subdocuments?专门测试索引或子文档?

In sql you can run queries, see execution time and other analytic metrics.在 sql 中,您可以运行查询、查看执行时间和其他分析指标。

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).我有一个巨大的 mongoDB 集合,想尝试不同的变体和索引,不知道如何测试它,很高兴看到找到一条记录需要多长时间..(我是 MongoDB 的新手)。 Thanks谢谢

There are two things here that you'll likely be familiar with.这里有两件事你可能很熟悉。

  1. Explain plans解释计划
  2. Slow Logs慢日志

Explain Plans解释计划

Here are some basic docs on explain. 这里有一些关于解释的基本文档 Running explain is as simple as db.foo.find(query).explain() .运行解释就像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.阅读上面和下面的文档,为您指明正确的方向。

Slow Logs慢日志

By default, slow logs are active with a threshold of 100ms.默认情况下,慢日志处于活动状态,阈值为 100 毫秒。 Here's a link to the full documentation on profiling. 这是有关分析的完整文档的链接 A couple of key points to get you started:帮助您入门的几个关键点:

Get/Set profiling:获取/设置分析:

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

See slow queries:查看慢查询:

db.system.profile.find()

MongoDB has a query profiler you can turn on. MongoDB 有一个可以打开的查询分析器。 See: http://www.mongodb.org/display/DOCS/Database+Profiler请参阅: http : //www.mongodb.org/display/DOCS/Database+Profiler

I recommend, based on my experience , to read mongologs with the mtools support ( https://github.com/rueckstiess/mtools ), there are lots of feature which help reading output .根据我的经验,我建议使用 mtools 支持( https://github.com/rueckstiess/mtools )阅读 mongologs,有很多功能可以帮助阅读输出。

For instance I found very useful the mlogFilter command eg:例如,我发现mlogFilter命令非常有用,例如:

mlogfilter.exe   [PATH_TO_FILE_LOG]  --slow --json | mongoimport --db logsTest -c logCollection --drop

Launching this command you will record all the slow queries in a table.启动此命令,您将在表中记录所有慢查询。

Activating mongoprofiler could be a problem for performance in production environment, so you can achieve the same results reading logs.在生产环境中激活 mongoprofiler 可能会导致性能问题,因此您可以在读取日志时获得相同的结果。

Consider also that the system.profile collection is capped , so you should check the size of the capped collection because otherwise you could not find the queries you're looking for.还要考虑system.profile集合是 ipped ,因此您应该检查system.profile集合的大小,否则您将无法找到您要查找的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM