2016-01-30 65 views
0

我使用mongo驱动程序2.2.2从我的rails应用程序连接。 我注意到我有太多打开的连接。 这是我的测试:正确的方法来关闭连接到mongodb从轨道

@db = Mongo::Client.new('mongodb://user:[email protected]:27017/db') 
# nothing to do! only for test! 
@db.close 

和我同时启动 - Rails应用程序,并在此之后我是创建单个请求我在调试模式下的应用程序和检查的mongod输出的MongoDB

$ rails server 
$ mongod 

2016-01-30T14:08:30.047+0200 [initandlisten] connection accepted from  127.0.0.1:65005 #1 (1 connection now open) 
2016-01-30T14:08:30.048+0200 [conn1] end connection 127.0.0.1:65005 (0 connections now open) 
2016-01-30T14:08:30.048+0200 [initandlisten] connection accepted from 127.0.0.1:65006 #2 (1 connection now open) 
2016-01-30T14:08:30.051+0200 [initandlisten] connection accepted from 127.0.0.1:65007 #3 (2 connections now open) 
2016-01-30T14:08:30.051+0200 [conn3] end connection 127.0.0.1:65007 (1 connection now open) 
2016-01-30T14:08:30.051+0200 [initandlisten] connection accepted from 127.0.0.1:65008 #4 (2 connections now open) 
2016-01-30T14:08:30.052+0200 [conn4] end connection 127.0.0.1:65008 (1 connection now open) 

在我的轨输出I见下:

D, [2016-01-30T14:08:30.046532 #12981] DEBUG -- : MONGODB | Adding localhost:27017 to the cluster. 
D, [2016-01-30T14:08:30.050656 #12981] DEBUG -- : MONGODB | Adding localhost:27017 to the cluster. 

我打算和关闭的mongod,并再次检查导轨输出:

D, [2016-01-30T14:08:50.060270 #12981] DEBUG -- : MONGODB | IOError 
D, [2016-01-30T14:09:00.065535 #12981] DEBUG -- : MONGODB | Connection refused - connect(2) for 127.0.0.1:27017 
D, [2016-01-30T14:09:10.066730 #12981] DEBUG -- : MONGODB | Broken pipe 
D, [2016-01-30T14:09:20.073243 #12981] DEBUG -- : MONGODB | Connection refused - connect(2) for 127.0.0.1:27017 
D, [2016-01-30T14:09:30.079056 #12981] DEBUG -- : MONGODB | Broken pipe 

最后我的问题:如何真正关闭连接到蒙戈? 我在做什么错?

回答