node.js what happens when maxSockets are reached?

◇◆丶佛笑我妖孽 提交于 2020-07-08 20:36:07

问题


I was wondering what happens when maxSockets is reached?

If I'm using a service that allows me to create a custom http.Agent and I specify maxSockets to 1. What happens when I try to issues multiple concurrent requests?

Will each request beyond the initial block until the initial is complete?? Then the socket would become available to the next request? and all others block? I would certainly assume so, but was not able to find anything in the docs specifically, and am brand new to socket programming.


回答1:


After maxSockets are in use, additional requests get queued until an active request completes and a socket is freed up to be used, at which point a pending request from the queue would be sent on the newly-freed socket.

Note this is technically queueing not blocking - the CPU and event loop continue to do useful work during this process.

Note also there is a maxSockets and queue on a per-origin ("host:port") basis (similar to browsers).

Also note that the default maxSockets is Infinity.



来源:https://stackoverflow.com/questions/33807728/node-js-what-happens-when-maxsockets-are-reached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!