当达到maxSockets时,node.js会发生什么? [英] node.js what happens when maxSockets are reached?

查看:85
本文介绍了当达到maxSockets时,node.js会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道到达 maxSockets 时会发生什么?

I was wondering what happens when maxSockets is reached?

如果我使用的服务允许我创建自定义 http.Agent 并指定 maxSockets 到1。当我尝试发出多个并发请求时会发生什么?

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.

推荐答案

使用maxSockets后,其他请求会排队直到活动的请求完成并且释放了套接字以供使用,这时来自队列的挂起请求将在新释放的套接字上发送。

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.

注意从技术上讲,这并不是在排队-在此过程中,CPU和事件循环会继续做有用的工作。

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

请注意,每个域上还有一个maxSockets和队列( 主机:端口)(类似于浏览器)。

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

还请注意,默认maxSockets为Infinity

这篇关于当达到maxSockets时,node.js会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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