简体   繁体   English

带有 Pymongo 的 DocumentDB 查询速度非常慢

[英]DocumentDB with Pymongo very slow to query

I'm using SageMaker notebooks together with a DocumentDB database.我将 SageMaker 笔记本与 DocumentDB 数据库一起使用。 I'm running my notebook inside the VPC where the DocumentDB is, yet, retrieving data is taking a huge amount of time.我在 DocumentDB 所在的 VPC 内运行我的笔记本,但是,检索数据需要花费大量时间。 I have roughly 60k documents in a collection.我的集合中大约有 60k 份文件。 Consider the code below:考虑下面的代码:

numbers = []
for x in collection.find({},{'number':1}):
   numbers.append(x)

The field number is just a string for identifying the document in another database.字段number只是一个字符串,用于标识另一个数据库中的文档。 As I've said, this should return a list with roughly 60k strings.正如我所说,这应该返回一个包含大约 60k 字符串的列表。 Nothing very large.没有什么很大的。 Yet, it's taking a very long time to run (more than 10min).然而,它需要很长时间才能运行(超过 10 分钟)。 Is this normal in DocumentDB?这在 DocumentDB 中是否正常? What might be going on?可能发生了什么? When using a MongoDB locally in my machine, this used to be way faster.在我的机器上本地使用 MongoDB 时,这过去要快得多。

First of all, the query without a filter is a collection scan.首先,没有过滤器的查询是集合扫描。 Depending on the working set size (how large are those documents) and the instance size you're using, is possible that the results are not cached, hence slower than what you used on your local machine.根据工作集大小(这些文档有多大)和您使用的实例大小,结果可能不会被缓存,因此比您在本地机器上使用的要慢。 Try forcing the use of the _id index, it may improve the query speed, like this:尝试强制使用 _id 索引,它可能会提高查询速度,如下所示:

for x in collection.find({'_id': {'$gt': 0}},{'number':1}):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM