Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the maximum numbers of open sockets #3268

Open
mcollina opened this issue May 16, 2024 · 5 comments
Open

Limit the maximum numbers of open sockets #3268

mcollina opened this issue May 16, 2024 · 5 comments
Labels
Agent Features or fixes related to the `Agent` class enhancement New feature or request Pool Features or fixes related to the `Pool` class

Comments

@mcollina
Copy link
Member

One of the first issues with "fetch failed" is that we don't limit the number of outgoing sockets, and the process runs out of them, triggering a timeout error.

I think we should add a limit of 127 per pool by default (or any other magic number)

@metcoder95
Copy link
Member

The global dispatcher or the overall default Client/Agent settings?

@mcollina
Copy link
Member Author

Both are good ideas.

@JoshMock
Copy link

The Elasticsearch client library (of which I am the current maintainer) currently has an open request from the Kibana team to support limiting the maximum open sockets and max idle sockets when keepalive is enabled. If this functionality is added to Undici, it would be helpful if it exposed options to limit the max open and max total sockets, both globally and per upstream target, as well as max free sockets for keepalive use cases, to provide parity with http.Agent's options:

  • maxFreeSockets: max free sockets when keepalive is enabled
  • maxSockets: max concurrent sockets per origin
  • maxTotalSockets: max concurrent sockets globally

I've not contributed to this library before, but would love to help add this functionality.

@metcoder95
Copy link
Member

Overall, I think this should be already doable (unless I'm overlooking at something).

By using Pool you can limit the number of connections (Client instance) that the pool can have. As a Client is mapped to a single Socket.

Ref: https://undici.nodejs.org/#/docs/api/Pool?id=parameter-pooloptions

The options listed should be ported to the Agent, as it can manage these options at a higher level, at the end, depending on the number of connections passed, can be a Pool of connections or a single connection per origin.

maxFreeSockets - maybe maxIdleConnections? Here the Pool and/or the Agent can be preemptive and destroy idle connections before waiting for more request to come.

maxTotalSockets - these should be ported to Agent I believe, as the Pool already has an option for that.

Would you like to send a PR for it?

@metcoder95 metcoder95 added enhancement New feature or request Pool Features or fixes related to the `Pool` class Agent Features or fixes related to the `Agent` class labels Aug 28, 2024
@mcollina
Copy link
Member Author

@JoshMock this is already possible at Pool level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agent Features or fixes related to the `Agent` class enhancement New feature or request Pool Features or fixes related to the `Pool` class
Projects
None yet
Development

No branches or pull requests

3 participants