Mongoose Constantly Opening Connections To MongoDB
Problem
I have a Node.js app running in EC2 connecting to MongoDB that is constantly opening and closing connections. When I tail the log file I see an endless stream of:
Sat Feb 2 23:29:06 [initandlisten] connection accepted from X.X.X.X:54291 #700437
Sat Feb 2 23:29:06 [conn700437] end connection X.X.X.X:54291
Sat Feb 2 23:29:06 [initandlisten] connection accepted from X.X.X.X:42206 #700438
Sat Feb 2 23:29:06 [conn700438] end connection X.X.X.X:42206
Sat Feb 2 23:29:06 [initandlisten] connection accepted from X.X.X.X:34255 #700439
Sat Feb 2 23:29:06 [conn700439] end connection X.X.X.X:34255
Sat Feb 2 23:29:07 [initandlisten] connection accepted from X.X.X.X:49641 #700440
Sat Feb 2 23:29:07 [conn700440] end connection X.X.X.X:49641
Sat Feb 2 23:29:08 [initandlisten] connection accepted from X.X.X.X:54293 #700441
The connection is made once during the app startup process like so:
app.configure('production', function() {
mongoose.connect('connstring');
})
app.configure(function database() {
mongoose.connection.on('error', function (err) {
console.log(err);
});
});
I have two questions.
First, is this normal?
Second, why would there not just be a few connections open for the connection pool?
Thanks
Related Articles
Solution
Looks like they may have added a fix to your issue in the last mongodb driver release here:
https://github.com/mongodb/node-mongodb-native/blob/master/HISTORY
1.2.11 2013-01-29 - Ping strategy now reuses sockets unless they are closed by the server to avoid overhead
https://npmjs.org/package/mongodb
Discussion
View additional discussion.