user1293081
user1293081

Reputation: 331

Hard limit connections Spring Boot

I'm working on a simple micro service written in Spring Boot. This service will act as a proxy towards another resources that have a hard concurrent connection limit and the requests take a while to process.

I would like to impose a hard limit on concurrent connections allowed to my micro service and rejecting any with either a 503 or on tcp/ip level. I've tried to look into different configurations that can be made for Jetty/Tomcat/Undertow but haven't figured out yet something completely convincing.

I found some settings regulating thread pools:

But if understand correctly these are all configuring thread pool sizes and will just result in connections being queued on some level.

This seems like really interesting, but this hasn't been merged in yet and is targeted for Spring Boot 1.5 , https://github.com/spring-projects/spring-boot/pull/6571

Am I out of luck using a setting for now? I could of course implement a filter but would rather block it on an earlier level and not have to reinvent the wheel. I guess using apache or something else in front is also an option, but still that feels like an overkill.

Upvotes: 0

Views: 1847

Answers (1)

bilak
bilak

Reputation: 4932

Try to look at EmbeddedServletContainerCustomizer

this gist could give you and idea how to do that.

TomcatEmbeddedServletContainerFactory factory = ...;
    factory.addConnectorCustomizers(connector ->
            ((AbstractProtocol) connector.getProtocolHandler()).setMaxConnections(10000));

Upvotes: 1

Related Questions