【问题标题】:MongoDB - too many connections w/ node.jsMongoDB - 使用 node.js 的连接太多
【发布时间】:2011-07-27 17:39:37
【问题描述】:

我在我的应用程序中使用 node.js 和 MongoDB。每当我使用 localhost 时,我都没有问题,并且应用程序运行良好。但是,在服务器上,数据库将我限制为 50 个连接。以下是日志示例:

Wed Jul 27 13:33:29 [initandlisten] waiting for connections on port 27017
Wed Jul 27 13:33:29 [websvr] web admin interface listening on port 28017
Wed Jul 27 13:34:50 [initandlisten] connection accepted from 127.0.0.1:42035 #1
Wed Jul 27 13:35:16 [initandlisten] connection accepted from 127.0.0.1:42181 #2
Wed Jul 27 13:35:16 [initandlisten] connection accepted from 127.0.0.1:42182 #3
Wed Jul 27 13:35:25 [initandlisten] connection accepted from 127.0.0.1:42249 #4
...
Wed Jul 27 13:36:09 [initandlisten] connection accepted from 127.0.0.1:42518 #50
Wed Jul 27 13:36:10 [initandlisten] connection accepted from 127.0.0.1:42524 #51
Wed Jul 27 13:36:10 [initandlisten] can't create new thread, closing connection

我正在使用命令mongod --maxConns=5000 启动该进程。有谁知道是什么导致了这个连接限制?

【问题讨论】:

  • 您找到解决方案了吗?

标签: mongodb node.js


【解决方案1】:

你能发布你用来连接的代码吗?如果您在每个请求上都连接到数据库,那么您将很快用完连接。在大多数情况下,最好在请求之间共享数据库连接,例如通过在应用启动时进行连接。

【讨论】:

    猜你喜欢
    • 2020-04-09
    • 1970-01-01
    • 2013-05-07
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    相关资源
    最近更新 更多