使用猫鼬时,在节点和mongo之间建立连接负载是否正常? [英] Is it normal to have loads of connections between node and mongo when using mongoose?

查看:49
本文介绍了使用猫鼬时,在节点和mongo之间建立连接负载是否正常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一个性能问题,我想知道是否有大约30个不同的连接(在群集配置中,每2个cpu上每个cpu大约15个)是否正常.这个数字似乎是一致的,但是我不确定为什么.

I am trying to figure out a performance issue and I was wondering if it is normal to have around 30 (I guess 15 per cpu on 2 cpus in cluster configuration) different connections. That number seams to be consistent but I am not sure why.

推荐答案

首先,请确保在Node进程重新启动时关闭连接.像这样:

Firstly, make sure you are closing your connections when the Node process restarts. Something like this:

process.on('SIGINT', function() {
  mongoose.connection.close(function () {
    console.log('Mongoose default connection disconnected through app termination');
    process.exit(0);
  });
});

还有更多关于管理默认Mongoose连接的信息: http://theholmesoffice.com/mongoose -connection-best-practice/

There's more on managing a default Mongoose connection here: http://theholmesoffice.com/mongoose-connection-best-practice/

还请注意,您可以为每个连接指定poolSize.默认值为5.

Also note that you can specify the poolSize per connection. The default is 5.

var uri = 'mongodb://localhost/test';
mongoose.createConnection(uri, { server: { poolSize: 4 }});

http://mongoosejs.com/docs/connections.html#connection_pools

这篇关于使用猫鼬时,在节点和mongo之间建立连接负载是否正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆