为什么当我同时发送50000多个查询时,我的node.js应用程序会“挂起”?

转移到其他问题

这是关于这个话题的最后一个问题 。 我从等式中删除了Express,并且通常清除了这个问题。


在你说出“傻瓜,串联”或类似的东西之前,我想提一下,这个代码永远不会用在生产上。 我search了几天,并进行testing,等等,现在我需要一些帮助。

如果你想看到更高层次的问题 – 在这里。

testing台:

  • Windows 10
  • Mongo 3.2.11
  • 节点6.11.3
  • Express 4.15.4

问题:

我有100000个元素,我想用find / findOne / whatever来检查一些集合。

当我这样做时:

Mongo很好 – 用日志,mongostat检查并简单地连接它并查询一些事情。

节点是部分正常 – 检查与一些延迟console.log工作正常, 如果我试图打开我的应用程序使用浏览器(这就是为什么我包括expression框架标签部分)它的加载,直到我跑到服务器超时。

有一个最简单的设置页面,没有任何连接到数据库或类似的东西:

router.get('/',function(req, res) { res.send({result:"OK"}); }); 

它挂起。 我什至手动赶上服务器超时检查这一点。

问题是为什么? 一切都是asynchronous的,所有的“资源”都很好,工作。 问题是什么?

PS的Mongostats显示有趣的事情 – 首先它显示每行添加2000-3000查询,然后0,0,0 …再次几千,然后再一次0。 这是一个粘贴


这是我的代码,如果你想要像我一样testing

  var t = setTimeout(function () { console.log("Timeout fired in 30 seconds"); }, 30 * 1000); var testArtists = []; for (i = 0; i < 100000; i++) { testArtists[i] = Math.floor(Math.random() * 16777215).toString(16); } async.map(testArtists, function (artist, callback) { db.get().collection('someCollection'). findOne( { "unimportant": testArtists[0] }, function (err, discogsArtist) { if (err) return callback(err); return callback(null, "OK"); } ); }, function (err, results) { if (err) return console.log(err); return console.log("somehow finished"); }); 

这里有一些我曾经遇到的错误,也许他们可以帮助,不知何故:

 { MongoError: connection 4 to localhost:27017 timed out at Function.MongoError.create (E:\blablabla\node_modules\mongodb-core\lib\error.js:29:11) at Socket.<anonymous> (E:\blablabla\node_modules\mongodb-core\lib\connection\connection.js:198:20) at Socket.g (events.js:292:16) at emitNone (events.js:86:13) at Socket.emit (events.js:185:7) at Socket._onTimeout (net.js:338:8) at ontimeout (timers.js:386:11) at tryOnTimeout (timers.js:250:5) at Timer.listOnTimeout (timers.js:214:5) name: 'MongoError', message: 'connection 4 to localhost:27017 timed out' } Something went wrong when retrieving an access token read ECONNRESET { Error: read ECONNRESET at exports._errnoException (util.js:1020:11) at TLSWrap.onread (net.js:568:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } { Error: read ECONNRESET at exports._errnoException (util.js:1020:11) at TLSWrap.onread (net.js:568:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } 

提前致谢!


更新1

更新我的代码插入对象 – 现在我们可以看到一些随机数的对象插入(60000-80000),然后一切都沉默。


更新2

Express实时查看日志。 根本没有电话,所以expression似乎是没有问题的。 目前。

更新3

在将游泳池连接到1000个连接之后,现在所有的东西都可以很快地工作,并及时完成。 但是这只是扩展解决scheme,就像“购买更多内存”一样。 我想知道为什么asynchronous使用数据库阻止从浏览器提供页面。 MongoClient池大小和节点服务页面之间有明确的联系。 当mongo驱动程序将所有分配的池取入时,Node停止为这些页面提供服务。 为什么? 而如何打呢?