在 MongoDB Atlas 仪表板查询分析器中,有一个 Num Yields 字段。这是什么?
最佳答案
来自 Database Profiler Output文档页面:
The number of times the operation yielded to allow other operations to complete. Typically, operations yield when they need access to data that MongoDB has not yet fully read into memory. This allows other operations that have data in memory to complete while MongoDB reads in data for the yielding operation. For more information, see the FAQ on when operations yield.
基本上 MongoDB 中的大多数数据库操作都有一个“屈服点”,即它可以将控制权让给其他操作的点。这通常是等待从磁盘加载数据。
简而言之,如果您看到大量的产出,则意味着查询花费了大量时间等待从磁盘加载数据。原因通常是:
- 返回或处理大量数据的查询。如果这是原因,请确保查询仅返回您需要的内容。然而,这在某些用例中可能无法避免(例如分析)。
- 未使用正确索引的低效查询,因此服务器被迫始终从磁盘加载完整文档。如果这是原因,请确保您已创建支持查询的适当索引。
- 服务器中的 RAM 较小,因此必须始终从磁盘加载数据。如果以上都不是,那么服务器对于手头的任务来说太小了。考虑升级服务器的硬件。
请注意,如果您不是一直看到它,那么高产量不一定是坏事。但是,如果您在定期运行的查询中看到这一点,那肯定不好。
关于MongoDB Atlas 探查器 : What is "Num Yields"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59589923/