On this page本页内容
The following sections describe techniques for evaluating operational performance.以下各节介绍了评估操作性能的技术。
MongoDB provides a database profiler that shows performance characteristics of each operation against the database. MongoDB提供了一个数据库探查器,可以显示针对数据库的每个操作的性能特征。Use the profiler to locate any queries or write operations that are running slow. 使用探查器查找运行缓慢的任何查询或写入操作。You can use this information, for example, to determine what indexes to create.例如,您可以使用这些信息来确定要创建哪些索引。
Starting in MongoDB 4.2, the profiler entries and the diagnostic log messages (i.e. mongod/mongos log messages) for read/write operations include:从MongoDB 4.2开始,用于读/写操作的探查器条目和诊断日志消息(即mongod/mongos日志消息)包括:
queryHash to help identify slow queries with the same query shape.queryHash可以帮助识别具有相同查询形状的慢速查询。planCacheKeyStarting in version 4.2 (also available starting in 4.0.6), secondary members of a replica set now log oplog entries that take longer than the slow operation threshold to apply. 从版本4.2开始(也可从4.0.6开始使用),副本集的次要成员现在会记录需要比慢速操作阈值更长时间才能应用的oplog条目。These slow oplog messages:这些缓慢的oplog消息:
diagnostic log.REPL component with the text applied op: <oplog entry> took <num>ms.REPL组件下,文本为applied op: <oplog entry> took <num>ms。May be affected by 可能会受到slowOpSampleRate, depending on your MongoDB version:slowOpSampleRate的影响,具体取决于您的MongoDB版本:
slowOpSampleRate. slowOpSampleRate的影响。slowOpSampleRate.slowOpSampleRate的影响。The profiler does not capture slow oplog entries.探查器不会捕获较慢的oplog条目。
For more information, see Database Profiler.有关更多信息,请参阅数据库探查器。
db.currentOp() to Evaluate mongod Operationsdb.currentOp()计算mongod操作The db.currentOp() method reports on current operations running on a mongod instance.db.currentOp()方法报告在mongod实例上运行的当前操作。
explain to Evaluate Query Performanceexplain来评估查询性能The cursor.explain() and db.collection.explain() methods return information on a query execution, such as the index MongoDB selected to fulfill the query and execution statistics. cursor.explain()和db.collection.explain()方法返回有关查询执行的信息,例如为完成查询和执行统计信息而选择的索引MongoDB。You can run the methods in queryPlanner mode, executionStats mode, or allPlansExecution mode to control the amount of information returned.您可以在queryPlanner模式、executionStats模式或allPlansExecution模式下运行这些方法,以控制返回的信息量。
To use 要在查询与表达式cursor.explain() on a query for documents matching the expression { a: 1 }, in the collection named records, use an operation that resembles the following in mongosh:{a:1}匹配的文档时使用cursor.explain(),请在名为records的集合中使用类似于mongosh中的以下操作:
db.records.find( { a: 1 } ).explain("executionStats")
Starting in MongoDB 4.2, the explain output includes:从MongoDB 4.2开始,解释输出包括:
queryHashplanCacheKeyFor more information, see Explain Results, 有关更多信息,请参阅解释结果、cursor.explain(), db.collection.explain(), and Analyze Query Performance.cursor.explain()、db.collection.explain()和分析查询性能。