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

Maximum simultaneous connections to a server. #151

Open
Dragomir-Ivanov opened this issue May 15, 2018 · 2 comments
Open

Maximum simultaneous connections to a server. #151

Dragomir-Ivanov opened this issue May 15, 2018 · 2 comments
Labels

Comments

@Dragomir-Ivanov
Copy link

Hi again,
Was wondering how to implement maximum connection count to a server ( within a server pool )?
So for example, if I have 3 servers defined, each will handle up to 5 connections, then It will result in 15 simultaneous connections at most.
Maybe something among the lines on Middleware?

Thanks again

@h2non h2non added the question label May 15, 2018
@h2non
Copy link
Contributor

h2non commented May 15, 2018

You can do it by keeping server distribution state in a pool of available slots by server using a simple counter, all of this within a middleware component that receives an outgoing request. Then, you should manage the request completion in order to free the taken slot. If you want traffic control on the client side in order to limit the amount of requests (not sure if this makes sense anyway), you would possibly need to use a waiting queue mechanism in case of all the slots are taken and await any new request.

If you want more sophisticated logic, you could use a content hashing algorithm for a truly uniform distribution in the pool. For node.js, you could use:
https://www.npmjs.com/package/consistent-hashing
https://www.npmjs.com/package/consistent-hash

@Dragomir-Ivanov
Copy link
Author

@h2non Thanks for the fast response. I am thinking if I go the route you have suggested with the simpler counter, didn't I loose the server balancing functionality. Perfectly the system should pick a server with a better score if not fully utilized at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants