PHP MongoDB 驱动程序的游标如何缓冲结果集?
当对mongodb进行查询时,它的游标如何处理内存中的结果集?游标是否立即检索与查询匹配的所有文档?或者它一次检索 1 个文档?或者它们被缓冲了?还是有我不知道的不同解决方案?
如果它是缓冲解决方案,它们如何存储在服务器/客户端上?客户端在本地保存了多少数据?
When queries are made to mongodb, how does it's cursor deal with the result set in memory? Does the cursor retrieve all documents which match the query, at once? or does it retrieve 1 document at a time? or are they buffered? or is there a different solution I don't know about?
If it's a buffered solution, how are they stored on the server/client? How much data does the client keep locally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MongoDB 有线协议在发布时对批量大小有规范一个查询。
基本前提是客户端驱动程序发出带有
numberToReturn
标志的查询。如果查询与numberToReturn
匹配,则仅将该号码返回给客户端。因此服务器有效地向客户端发送了“一批”。如果客户端循环执行整个批次,客户端会发出 getmore< /a> 请求并接收下一批。同时,服务器不需要将所有结果加载到内存中,只需满足客户端的请求即可。
PHP 驱动程序消除了大部分复杂性。您对驱动程序所做的只是请求下一个项目,驱动程序将在适当的情况下处理
getmore
。就大小而言,您将获得 Max BSON size 或
numberToReturn
中较小的一个。因此,如果文档太大,您可以设置最大 BSON 大小,以防止一次发送太多数据。获取更多详细信息的最佳位置是实际代码。
The MongoDB wire protocol has specifications for batch size when issuing a query.
The basic premise is that the client driver issues a query with
numberToReturn
flag. If the query matches over thenumberToReturn
, then only that number is returned to the client.So the server effectively sends one "batch" to the client. If the client cycles through the whole batch, the client issues a getmore request and receives the next batch. In the meanwhile, the server does not need to load all results into memory, only enough to satisfy the client's request.
The PHP driver abstracts away much of this complexity. All you do with the driver is request the next item and the driver will handle the
getmore
where appropriate.In terms of size, you will get the smaller of Max BSON size or
numberToReturn
. So if the documents are too big, you may hit Max BSON size to prevent sending too much data at once.The best spot to get any more details is the actual code.