Reputation: 163
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")));
}
}
Upvotes: 4
Views: 529
Reputation: 780
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")));
}
}
Upvotes: 2