Node JS如何限制最大套接字数 [英] Node JS how to limit maximum number of sockets

查看:66
本文介绍了Node JS如何限制最大套接字数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以设置服务器可以处理的最大套接字数?像这样:maxSocket = 2并从套接字尝试连接的3次尝试中自动拒绝该连接?

is it possibile to set the maximum number of sockets that my server can handle? Something like: maxSocket = 2 and from the 3 attempt of a socket to connect automatically refuse that connection?

谢谢

推荐答案

maxSockets的默认值为 Infinity ,它确定每个主机的套接字数限制.请参阅官方文档: https://nodejs.org/api/http.html#http_agent_maxsockets

The default maxSockets value is Infinity and it determines the limit of number of sockets per host. See official docs: https://nodejs.org/api/http.html#http_agent_maxsockets

您可以使用以下代码段手动设置maxSockets限制

You can manually set maxSockets limit using the following code snippet

require('http').globalAgent.maxSockets = 10

globalAgent :代理的全局实例,用作所有HTTP客户端请求的默认实例.

globalAgent: Global instance of Agent which is used as the default for all HTTP client requests.

这篇关于Node JS如何限制最大套接字数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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