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

Provide a "MaxConcurrentConnections" handler #143

Open
Lukasa opened this issue Sep 14, 2021 · 1 comment
Open

Provide a "MaxConcurrentConnections" handler #143

Lukasa opened this issue Sep 14, 2021 · 1 comment
Labels
kind/enhancement Improvements to existing feature.

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Sep 14, 2021

Many kinds of servers want to limit the maximum number of concurrent connections they'll accept in order to bound their resource commitment. It's a bit non-obvious how to do this in NIO, but it's not terribly difficult to do. Things that are non-obvious but straightforward are a fairly good candidate for implementation in this module.

In this case, the mechanism for achieving this is to provide a ChannelDuplexHandler that users would insert .first in the server channel pipeline (using serverChannelInitializer). This handler would delay the read call in cases where the maximum number of connections has been reached. It can keep track of new connections using inboundIn and it can record when connections close by using the Channel.closeFuture.

A really great implementation would be able to tolerate both a "flexible" maximum and a hard cap. In hard-cap mode we'd need to set maxMessagesPerRead to 1 in order to prevent over-reading (though the handler could dynamically twiddle this setting). In "flexible" mode we'd allow a slight overrun, up to maxMessagesPerRead - 1 extra connections.

@Lukasa Lukasa added the kind/enhancement Improvements to existing feature. label Sep 14, 2021
@Davidde94
Copy link
Contributor

I'm pretty sure I did a very crude version of this in my first weeks at Apple, I might even have a very basic implementation lying around on a branch somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

2 participants