node.js - MongoDB 不报告关闭连接

标签 node.js mongodb

我正在运行getting started tutorial评估 MongoDB 在生产中的使用。

跟踪服务器日志显示以下内容:在最后 5 行中,mongod 报告它正在关闭连接,但打开的连接数计数并未减少。这是预期的行为吗?

$ tail -f /usr/local/var/log/mongodb/mongo.log
2015-11-29T15:10:13.425+0000 I JOURNAL  [journal writer] Journal writer thread started
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] MongoDB starting : pid=86710 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=As-MacBook-Air.local
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] 
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] db version v3.0.7
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] git version: nogitversion
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] build info: Darwin As-MacBook-Air.local 13.4.0 Darwin Kernel Version 13.4.0: Wed Mar 18 16:20:14 PDT 2015; root:xnu-2422.115.14~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] allocator: system
2015-11-29T15:10:13.425+0000 I CONTROL  [initandlisten] options: { config: "/usr/local/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, storage: { dbPath: "/usr/local/var/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/usr/local/var/log/mongodb/mongo.log" } }
2015-11-29T15:10:13.435+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
2015-11-29T15:14:21.158+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52667 #1 (1 connection now open)
2015-11-29T15:14:21.169+0000 I NETWORK  [conn1] end connection 127.0.0.1:52667 (0 connections now open)
2015-11-29T15:14:21.175+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52668 #2 (1 connection now open)
2015-11-29T15:14:21.176+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52669 #3 (2 connections now open)
2015-11-29T15:14:21.176+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52670 #4 (3 connections now open)
2015-11-29T15:14:21.176+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52671 #5 (4 connections now open)
2015-11-29T15:14:21.179+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52672 #6 (5 connections now open)
2015-11-29T15:14:21.183+0000 I NETWORK  [conn2] end connection 127.0.0.1:52668 (4 connections now open)
2015-11-29T15:14:21.184+0000 I NETWORK  [conn3] end connection 127.0.0.1:52669 (3 connections now open)
2015-11-29T15:14:21.184+0000 I NETWORK  [conn4] end connection 127.0.0.1:52670 (2 connections now open)
2015-11-29T15:14:21.184+0000 I NETWORK  [conn5] end connection 127.0.0.1:52671 (1 connection now open)
2015-11-29T15:14:21.184+0000 I NETWORK  [conn6] end connection 127.0.0.1:52672 (0 connections now open)
2015-11-29T15:25:39.136+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52799 #7 (1 connection now open)
2015-11-29T15:25:39.137+0000 I NETWORK  [conn7] end connection 127.0.0.1:52799 (0 connections now open)
2015-11-29T15:25:39.142+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52800 #8 (1 connection now open)
2015-11-29T15:25:39.142+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52801 #9 (2 connections now open)
2015-11-29T15:25:39.144+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52802 #10 (3 connections now open)
2015-11-29T15:25:39.144+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52803 #11 (4 connections now open)
2015-11-29T15:25:39.145+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52804 #12 (5 connections now open)
2015-11-29T15:25:39.153+0000 I INDEX    [conn9] allocating new ns file /usr/local/var/mongodb/test.ns, filling with zeroes...
2015-11-29T15:25:39.209+0000 I STORAGE  [FileAllocator] allocating new datafile /usr/local/var/mongodb/test.0, filling with zeroes...
2015-11-29T15:25:39.209+0000 I STORAGE  [FileAllocator] creating directory /usr/local/var/mongodb/_tmp
2015-11-29T15:25:39.328+0000 I STORAGE  [FileAllocator] done allocating datafile /usr/local/var/mongodb/test.0, size: 64MB,  took 0.118 secs
2015-11-29T15:25:39.374+0000 I WRITE    [conn9] insert test.restaurants query: { address: { street: "2 Avenue", zipcode: "10075", building: "1480", coord: [ -73.9557413, 40.7720266 ] }, borough: "Manhattan", cuisine: "Italian", grades: [ { date: new Date(1412121600000), grade: "A", score: 11 }, { date: new Date(1389830400000), grade: "B", score: 17 } ], name: "Vella", restaurant_id: "41704620", _id: ObjectId('565b18f333b46874536e90de') } ninserted:1 keyUpdates:0 writeConflicts:0 numYields:0 locks:{ Global: { acquireCount: { r: 2, w: 2 } }, MMAPV1Journal: { acquireCount: { w: 8 }, acquireWaitCount: { w: 1 }, timeAcquiringMicros: { w: 179 } }, Database: { acquireCount: { w: 1, W: 1 } }, Collection: { acquireCount: { W: 1 } }, Metadata: { acquireCount: { W: 4 } } } 221ms
2015-11-29T15:25:39.374+0000 I COMMAND  [conn9] command test.$cmd command: insert { insert: "restaurants", documents: [ { address: { street: "2 Avenue", zipcode: "10075", building: "1480", coord: [ -73.9557413, 40.7720266 ] }, borough: "Manhattan", cuisine: "Italian", grades: [ { date: new Date(1412121600000), grade: "A", score: 11 }, { date: new Date(1389830400000), grade: "B", score: 17 } ], name: "Vella", restaurant_id: "41704620", _id: ObjectId('565b18f333b46874536e90de') } ], ordered: true } keyUpdates:0 writeConflicts:0 numYields:0 reslen:40 locks:{ Global: { acquireCount: { r: 2, w: 2 } }, MMAPV1Journal: { acquireCount: { w: 8 }, acquireWaitCount: { w: 1 }, timeAcquiringMicros: { w: 179 } }, Database: { acquireCount: { w: 1, W: 1 } }, Collection: { acquireCount: { W: 1 } }, Metadata: { acquireCount: { W: 4 } } } 221ms
2015-11-29T15:25:39.384+0000 I NETWORK  [conn8] end connection 127.0.0.1:52800 (4 connections now open)
2015-11-29T15:25:39.384+0000 I NETWORK  [conn9] end connection 127.0.0.1:52801 (4 connections now open)
2015-11-29T15:25:39.384+0000 I NETWORK  [conn10] end connection 127.0.0.1:52802 (3 connections now open)
2015-11-29T15:25:39.385+0000 I NETWORK  [conn11] end connection 127.0.0.1:52803 (2 connections now open)
2015-11-29T15:25:39.385+0000 I NETWORK  [conn12] end connection 127.0.0.1:52804 (2 connections now open)

我启动了 MongoDB 服务器:

$ mongod --config /usr/local/etc/mongod.conf

其他详细信息:

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.9.5
BuildVersion:   13F1096
$ mongod -version
db version v3.0.7
git version: nogitversion
$ cat /usr/local/etc/mongod.conf
systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1

最佳答案

根据我的经验,MongoDB 持有一个根据请求分配的连接队列,而不是每个请求都会转换为打开连接并在传递响应时关闭它。

在使用同一 MongoDB 处理多个服务时,我经历过大量连接,我们必须在应用程序中限制创建的连接数量并重用相同的连接,而不是为每个请求创建一个新连接。

希望有帮助。

关于node.js - MongoDB 不报告关闭连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33984620/

相关文章:

node.js - node.bcrypt.js 如何比较没有加盐的散列密码和明文密码?

javascript - 如何使用 GraphQL 将二进制数据发送回客户端

javascript - 如何定义搜索词框以使用 Twitter 流 API 和meteor.js 搜索用户的特定时间线

Spring 数据 mongodb 存储库。如何通过 ID 列表进行搜索?

node.js - 使用 node-postgres 获取 UTC 格式的 Postgres "timestamp without timezone"

javascript - 在 Express.js 中,如何将通配符路由设置为不匹配 Assets 文件?

node.js - webpack 生产构建 IIS 后出现空白页面

mongodb - Mongo 多对多

node.js - 为什么 mongodb 或 mongoose 在字符串查询中添加引号?

javascript - MongoDB 使用 Async.js 与 $in 保持顺序