MongoDB Atlas Profiler:什么是 "Num Yields"?

MongoDB Atlas Profiler: What is "Num Yields"?

在 MongoDB Atlas 仪表板查询分析器中,有一个 Num Yields 字段。这是什么?

Screenshot

来自 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 中的大多数数据库操作都有一个 "yield point",即它可以将控制权让给其他操作的点。这通常是等待从磁盘加载数据。

简而言之,如果您看到大量产出,则意味着查询花费了大量时间等待从磁盘加载数据。原因通常是:

  • 返回或处理大量数据的查询。如果这是原因,请确保仅查询 returns 您需要的内容。然而,这在某些用例中可能无法避免(例如分析)。
  • 未使用正确索引的低效查询,因此服务器被迫一直从磁盘加载完整文档。如果这是原因,请确保您已创建支持查询的正确索引。
  • 服务器RAM小,所以数据必须一直从磁盘加载。如果 none 以上,那么服务器对于手头的任务来说太小了。考虑升级服务器硬件。

请注意,如果您不是一直看到它,那么高产量并不一定是坏事。但是,如果您在经常 运行 的查询中看到它肯定不好。