英文:
Runaway mongodb connections
问题
I have set my MongoDB "poolSize": 100
, but the connections count in the metrics keeps rising to 1,500 before the server resets them. Each API call to my Node.js application adds a new connection. Here's my server.js function for setting up the database connection:
const db = mongoose.connect(config.db, {
'useNewUrlParser': true,
'useUnifiedTopology': true,
'useFindAndModify': false,
'useCreateIndex': true,
'poolSize': 100
}).then((db) => {
const app = require('./config/express')(db);
require('./config/passport')();
app.listen(config.port);
exports = module.exports = app;
console.log('App started on port ' + config.port + ', node_env: ' + process.env.NODE_ENV);
}).catch(error => { throw error});
除了设置"poolSize": 100
之外,我还需要做什么来设置池大小吗?
英文:
So I have set my mongodb "poolSize": 100
but I'm still seeing my connections count in the metrics skyrocket up to 1,500 before the server forces it them to reset. Every single API call to my node.js application is adding a new connection. Here is my server.js function for setting up my db connection:
const db = mongoose.connect(config.db, {
'useNewUrlParser': true,
'useUnifiedTopology': true,
'useFindAndModify': false,
'useCreateIndex': true,
'poolSize': 100
}).then((db) => {
const app = require('./config/express')(db);
require('./config/passport')();
app.listen(config.port);
exports = module.exports = app;
console.log('App started on port ' + config.port + ', node_env: ' + process.env.NODE_ENV);
}).catch(error => { throw error});
Is there something more to setting up pool size that I need to do in addition to my "poolSize": 100
setting above?
答案1
得分: 1
没有名为poolSize
的配置选项,它不受mongoose
或MongoDB NodeJS Driver
支持。支持的两个选项是maxPoolSize
和minPoolSize
。您需要使用maxPoolSize
来限制最大连接数。在这里查看支持的选项列表:
英文:
There is no configuration option named poolSize
supported by mongoose
or MongoDB NodeJS Driver
. The two supported options are maxPoolSize
and minPoolSize
. You need to use maxPoolSize
to limit the maximum number of connections. Check the list of supported options here:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论