为什么node.js一次只能处理六个请求? [英] Why is node.js only processing six requests at a time?

查看:105
本文介绍了为什么node.js一次只能处理六个请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个node.js服务器,该服务器将REST API实现为中央服务器的代理,而中央服务器具有一个稍有不同且很不对称的REST API.

We have a node.js server which implements a REST API as a proxy to a central server which has a slightly different, and unfortunately asymmetric REST API.

运行在各种浏览器中的客户端要求节点服务器从中央服务器获取任务.节点服务器从中央服务器获取所有任务ID的列表,并将其返回给客户端.然后,客户端通过代理对每个ID进行两次REST API调用.

Our client, which runs in various browsers, asks the node server to get the tasks from the central server. The node server gets a list of all the task ids from the central one and returns them to the client. The client then makes two REST API calls per id through the proxy.

据我所知,这些工作都是异步完成的.在控制台日志中,启动客户端时,它看起来像这样:

As far as I can tell, this stuff is all done asynchronously. In the console log, it looks like this when I start the client:

Requested GET URL under /api/v1/tasks/*: /api/v1/tasks/

这需要花费几秒钟的时间才能从中央服务器获取列表.收到响应后,服务器会很快将其拒绝:

This takes a couple seconds to get the list from the central server. As soon as it gets the response, the server barfs this out very quickly:

Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/438
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/438
Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/439
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/439
Requested GET URL under /api/v1/tasks/id/:id :/api/v1/tasks/id/441
Requested GET URL under /api/v1/workflow/id/:id :/api/v1/workflow/id/441

然后,每当一对请求从中央服务器得到结果时,就会很快将另外两行驳倒.

Then, each time a pair of these requests gets a result from the central server, another two lines is barfed out very quickly.

所以看来我们的node.js服务器一次只愿意发出六个请求.

So it seems our node.js server is only willing to have six requests out at a time.

推荐答案

这是浏览器中并发连接数的限制:

It's the limit on number of concurrent connections in the browser:

多少个并发AJAX(XmlHttpRequest)流行的浏览器允许请求吗?

我已对其他答案进行了投票,因为它们帮助我诊断了问题.提示是节点的套接字限制为5,而我一次得到6. Chrome中的限制是6,这就是我用来测试服务器的限制.

I have upvoted the other answers, as they helped me diagnose the problem. The clue was that node's socket limit was 5, and I was getting 6 at a time. 6 is the limit in Chrome, which is what I was using to test the server.

这篇关于为什么node.js一次只能处理六个请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆