我有一个在 EC2 中运行的 Node.js 应用程序连接到不断打开和关闭连接的 MongoDB。当我跟踪日志文件时,我看到源源不断的:
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
在应用程序启动过程中建立一次连接,如下所示:
app.configure('production', function() {
mongoose.connect('connstring');
})
app.configure(function database() {
mongoose.connection.on('error', function (err) {
console.log(err);
});
});
我有两个问题。
首先,这正常吗?
其次,为什么连接池不会只打开几个连接?
谢谢