Runaway mongodb connections

huangapple go评论95阅读模式
英文:

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的配置选项,它不受mongooseMongoDB NodeJS Driver支持。支持的两个选项是maxPoolSizeminPoolSize。您需要使用maxPoolSize来限制最大连接数。在这里查看支持的选项列表:

Mongoose配置选项

英文:

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:

Mongoose Config Options

huangapple
  • 本文由 发表于 2023年5月30日 05:06:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360321.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定