Pass
Pass

Reputation: 1501

Is it normal to have loads of connections between node and mongo when using mongoose?

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.

Upvotes: 1

Views: 285

Answers (1)

Simon Holmes
Simon Holmes

Reputation: 303

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);
  });
});

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

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

Upvotes: 1

Related Questions