MONGODB:与Atlas群集的连接非常慢,使用900记录的简单查找查询需要30-40秒
我们正在使用的 Mongodb atlas 集群和 Nodejs 配置:
Cluster: M10
RAM: 2GB
Mongodb version: 4.4
Mongoose version: ^6.1.5
Nodejs version: 12.x
我们在代码库中与云提供商 AWS 一起使用无服务器架构,并尝试从部署 mongodb 集群的同一 AWS 区域法兰克福连接到集群。我们的聚合查询使用用户 ID 的简单匹配条件来获取特定用户的数据,但查询需要大约 30-40 秒才能返回文档。在文档数量较少的情况下不会观察到这种行为,只有当文档数量增加时才会出现这种情况。
这是聚合查询 -
{
$match: {
user_id: 1
}
}
我们也尝试使用简单的查找来查询相同的数据,但问题仍然存在。 查找查询是 -
{
user_id: 1
}
当在 Atlas 解释计划上运行相同的查询时,它会在 1-2 毫秒内执行,而当集群从本地服务器连接时,相同的查询需要几秒钟才能执行。 为了使查询更快,我们甚至在用户 ID 上添加了索引,并在查询时添加了索引提示。还添加了限制和偏移量来批量获取数据,但似乎没有任何改变查询的响应时间。
文档统计如下:
Total number of documents: 1925
Documents that are examined and returned: 975
Size of the collection being queried: 18.3 MB
这里可能存在什么问题?是 RAM 大小不足以处理数据,我们需要升级集群,还是我们错过了一些非常基本的东西?
PS 目前我们的集群还没有应用 VPC。
Mongodb atlas cluster and nodejs configuration we are using:
Cluster: M10
RAM: 2GB
Mongodb version: 4.4
Mongoose version: ^6.1.5
Nodejs version: 12.x
We are using Serverless architecture in our codebase along with cloud provider AWS and are attempting to connect to cluster from the same AWS region Frankfurt in which the mongodb cluster is deployed. Our aggregation query is with a simple match condition on user id to fetch data for a particular user, but the query takes around 30-40 seconds to return the documents. This behaviour was not observed with lesser number of documents, it occurred only when documents increased in number.
This is the aggregation query -
{
$match: {
user_id: 1
}
}
We have also tried querying the same data with simple find, but the issue still persists.
Find query is -
{
user_id: 1
}
When the same query is run on Atlas explain plan it is executed within 1-2 ms while the same takes seconds to execute when the cluster is connected from local server.
For making the query fast, we have even added the index on the user id and hint of the index with query. Also added limit and offset to fetch data in batches, but nothing seems to change the response time of the query.
Document stats are as given below:
Total number of documents: 1925
Documents that are examined and returned: 975
Size of the collection being queried: 18.3 MB
What could be the issue here? Is it the RAM size that is not sufficient to handle the data and we need to upgrade the cluster or we are missing out on something very basic?
P.S. We do not have VPC applied on our cluster as of now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论