Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not test Spring Boot Webflux performance with Apache Bench

I met a problem when testing the performance of spring reactive projects with Apache Bench.

ab http://localhost:8080/hi

The result shows timeout.

But it's OK for curl http://localhost:8080/hi

My project uses Spring boot version is 2.0.0.M6. I will paste some of the code.

pom.xml is

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-reactor-netty</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>

MyRouter.java

@Component
public class MyRouter {
    private static final Logger logger = LoggerFactory.getLogger(MyRouter.class);
    @Bean
    RouterFunction<ServerResponse> router(PersonHandler personHandler) {
        return route(GET("/hi"), request -> ok().body(BodyInserters.fromObject("hello")));
    }
}
like image 820
Jomy Avatar asked Oct 20 '25 10:10

Jomy


1 Answers

It's due to an ab's bug when call netty server.

To workaround it, just add "Connection: closed" into response header. But this is not a final solution.

MyRouter.java

@Component
public class MyRouter {
    private static final Logger logger = LoggerFactory.getLogger(MyRouter.class);
    @Bean
    RouterFunction<ServerResponse> router(PersonHandler personHandler) {
        return route(GET("/hi"), request -> ok().header("Connection", "close").body(BodyInserters.fromObject("hello")));
    }
}
like image 171
Aura Avatar answered Oct 22 '25 02:10

Aura



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!