0

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?

Thanks

2
  • I forgot to mention that I already have a counter in my server app, and whenever a client connects succesfully, check that counter and if needed manually call socket.disconnect(). I wonder if there is a more efficient solution. Commented Oct 9, 2018 at 13:44
  • think this is what you are referring to? stackoverflow.com/questions/19088253/… Commented Oct 9, 2018 at 13:48

2 Answers 2

0

In Node.js, you can set the maximum number of connections per origin. If maxSockets is set, the low-level HTTP client queues requests and assigns them to sockets as they become available.

Ref URL from AWS JS SDK

According to Node.js Doc,

By default set to Infinity. Determines how many concurrent sockets the agent can have open per origin. Origin is either a 'host:port' or 'host:port:localAddress' combination.

Conventionally, they recommend 25~50, I guess.

Sign up to request clarification or add additional context in comments.

Comments

0

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

You can manually set maxSockets limit using the following code snippet

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.