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")));
}
}
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")));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With