“服务器 x 超时"在 MongoDB 聚合期间 [英] "Server x timed out" during MongoDB aggregation
问题描述
我有一个脚本,它定期在 mongodb 集合上运行聚合.随着数据集的增长,聚合所需的时间也在增长.我的聚合脚本最近一直停止工作,错误日志显示:<代码>错误:{ [MongoError: server
I have a script that periodically runs aggregation on a mongodb collection. As the dataset has grown, the amount of time it takes to aggregate has also grown. My aggregation script has recently stopped working consistently, and the error logs show:
error: { [MongoError: server <x> timed out]
name: 'MongoError',
message: 'server <x> timed out' }
I've tried debugging this, and the only pattern I can find is that this timeout seems to only occur when the aggregation takes longer than 2 minutes (it times out right around 2m). Does anyone have additional debugging tips for this? The 2-minute thing is giving me the impression that I just need to configure some timeout somewhere but I can't figure out where or if i'm just falling into a red-herring trap.
关于系统配置:这个聚合脚本是一个 node.js (v5.9.1) 应用程序,运行在一个基于 alpine 的 docker (v1.9.1) 容器中.它使用 mongodb
节点驱动程序 (v2.1.19).运行 mongod (v3.2.6) 的单个 mongodb 服务器(尽管这也发生在具有 replSet 的单独环境中)
About the system configuration: This aggregation script is a node.js (v5.9.1) application running in an alpine-based docker (v1.9.1) container. It uses the mongodb
node driver (v2.1.19). Single mongodb server (though this is also happening in a separate environment with a replSet) running mongod (v3.2.6)
推荐答案
我遇到了同样的日志时间聚合问题.我想我有你的解决方案.
I got the same problem for logs time aggregation. I think I have the solution for you.
我发现选项 socketTimeoutMS
对此负责.检查您的 mongo_client.js 默认 socketTimeoutMS
值.对我来说是 2min
.Mongodb 模块版本 2.1.18.
I found that the option socketTimeoutMS
is responsible for that.
Check your mongo_client.js default socketTimeoutMS
value. For me it was 2min
. Mongodb module version 2.1.18.
所以只需将此选项添加到您的网址中即可:
So just add this option into your url :
mongodb://localhost:27017/test?maxPoolSize=2&socketTimeoutMS=60000
它会将 timeout
设置为 10 分钟.这对我有用.
It will set timeout
to 10 mins. That does the trick for me.
这篇关于“服务器 x 超时"在 MongoDB 聚合期间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!