Lokesha S
Lokesha S

Reputation: 61

How to configure netty in spring boot 2

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

Upvotes: 9

Views: 20712

Answers (2)

Brian Clozel
Brian Clozel

Reputation: 59056

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);
    }
}

Upvotes: 10

Meghana Randad
Meghana Randad

Reputation: 450

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

Upvotes: -3

Related Questions