WebFlux async processing

怎甘沉沦 提交于 2019-12-23 04:34:29

问题


I am trying to evaluate Spring WebFlux and advantages of reactive processing. To do so I have implemented tiny project with jetty server setup that exposes same endpoint over sync jersey, async jersey and spring web-flux.

Repository can be found here https://github.com/aakhmerov/nio-test

As far as I can see current implementation is not faster then synchronous processing implemented over jersey. Which makes me think that I have made some mistake in setup.

Flux setup is done over annotations through classes

com.aakhmerov.test.flux.FluxConfig:

@Configuration
@ComponentScan(basePackages = "com.aakhmerov.test.flux")
@EnableWebFlux
public class FluxConfig {
}

com.aakhmerov.test.flux.FluxStatusRestService:

@RestController
@RequestMapping(value = "/flux/status")
public class FluxStatusRestService {

  @Autowired
  private StatusCheckingService statusCheckingService;

  @GetMapping("/connection")
  public Mono<ConnectionStatusDto> getConnectionStatus() {
    ConnectionStatusDto result = 
      statusCheckingService.getConnectionStatus();
    return Mono.just(result);
  }
}

which is then wrapped into servlet and plugged into embedded jetty server. The questin is if it's using async boundry out of the box at all or some extra configuration is required.

Here are sample results of a test run:

Endpoint: [http://localhost:8090/api/status/async/threaded-connection] 
 error count [0] 
 avg duration [3993] ms

Endpoint: [http://localhost:8090/api/status/connection] 
 error count [0] 
 avg duration [4595] ms

Endpoint: [http://localhost:8090/api/status/async/unmanaged-threaded-connection] 
 error count [0] 
 avg duration [2455] ms

Endpoint: [http://localhost:8090/flux/status/connection] 
 error count [0] 
 avg duration [4850] ms

Endpoint: [http://localhost:8090/api/status/async/connection] 
 error count [0] 
 avg duration [1963] ms

I am not claiming this test to be perfect in any sort, but webflux endpoint is way off behind at the moment, which makes me wonder what is going wrong there.

Thank you in advance.

来源:https://stackoverflow.com/questions/47872545/webflux-async-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!