我正在使用 Doctrine MongoDB ODM 从远程 MongoDB 数据库中获取少量文档。
我确认查询只用了 1 毫秒就找到了大约 12 个匹配的文档。(即 'millis':1 来自解释输出)。但是遍历结果大约需要 250 毫秒。
当我尝试以下选项的组合时,我无法获得任何性能提升
- 选择('名称')
- 水合物(假)
- 急切光标(真)
- 限制(1)
我怎样才能最大限度地减少这种延迟?
更新:示例代码的更多解释
$qb = $dm->createQueryBuilder('Books');
$books = $qb->select('name')
->field('userId')->equals(123)
->field('status')->equals('active')
->eagerCursor(true) // Fetch all data at once
->getQuery()
->execute();
/**
* Due to using Eager Cursor, the database connection should be closed and
* all data should be in memory now.
*/
// POINT A
foreach($books as $book) {
// I do nothing here. Just looping through the results.
}
// POINT B.
/**
* From POINT A to POINT B takes roughly 250ms when the query had 12 matching docs.
* And this doesn't seem to be affected much by the number of records matched.
* As the data is already in the memory, I expected this to be done in range of
* 5~10ms, not 250ms.
*
* Am I misunderstanding the meaning of Eager Cursor?
*/