翻译或纠错本页面

评估当前操作的性能

下面的部分描述了用于评估操作性能的技术。

使用数据库探查器评估针对数据库的操作

MongoDB提供了一个数据库探查器来展示针对数据库的每个操作的性能特性。你可以使用探查器定位到任一运行缓慢的查询或写操作。然后,你可以使用这些信息,例如,你可以运用这些信息来决定创建怎样的索引。

更多信息,请参见 Database Profiling

使用 db.currentOp() 评估 mongod 操作

The db.currentOp() method reports on current operations running on a mongod instance.

Use explain to Evaluate Query Performance

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. You can run the methods in queryPlanner mode, executionStats mode, or allPlansExecution mode to control the amount of information returned.

Example

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 the mongo shell:

db.records.find( { a: 1 } ).explain("executionStats")

For more information, see Explain Results, cursor.explain(), db.collection.explain(), and 分析查询性能.