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.

Problem courtesy of: Pass


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

There's more on managing a default Mongoose connection here:

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

Solution courtesy of: Simon Holmes


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.