9

By default spring web flux uses netty which is single threaded event loop. How to configure spring boot so that a thread will be created for each core.

Thanks,

Lokesh

2 Answers 2

10

As described in the Spring Boot reference documentation, you can customize the Reactor Netty web server with a NettyServerCustomizer.

Here's an example with Spring Boot 2.1:

@Component
public class MyNettyWebServerCustomizer
        implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {

    @Override
    public void customize(NettyReactiveWebServerFactory factory) {
        factory.addServerCustomizers(new EventLoopNettyCustomizer());
    }
}

class EventLoopNettyCustomizer implements NettyServerCustomizer {

    @Override
    public HttpServer apply(HttpServer httpServer) {
        LoopResources loopResources = LoopResources.create(...);
        return httpServer.runOn(loopResources);
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

tcpConfiguration deprecated. no alternative provided
@RamPrakash I've updated my code snippet. A better, shorter and more flexible alternative is provided.
@BrianClozel Thanks. Can I ask one question related to this? Looks like there is no way to increase the boss thread count. Or boss is renamed to selector?
-3

You can change your dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- Exclude the Tomcat dependency -->
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- Use Jetty instead -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html

1 Comment

The question is not about changing the server. how to run a single-threaded netty attach to each processor

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.