首页 文章

Spring WebFlux WebClient的弹性和性能

提问于
浏览
15

我只是通过示例PoC项目在简单的常见场景中测试一些阻塞/非阻塞解决方案 .

场景:

  • 有一个非常缓慢的休息阻塞 endpoints - 每个请求花费200毫秒 .

  • 还有其他 - 客户端应用程序,它调用此慢 endpoints .

我已经使用WebFlux测试了当前(阻塞)Spring启动客户端(tomcat),Spring Boot 2.0(netty) - WebClient,Ratpack和Lagom . 在每种情况下,我都通过gatling测试简单场景(100-1000个用户/秒)强调了客户端应用程序 .

我已经测试了ratpack和lagom作为参考非阻塞io服务器,以将结果与spring boot(阻塞和非阻塞)进行比较 .

在所有情况下,我都有预期的结果,除了Spring boot 2.0测试 . 它仅适用于小负载水平,但即便如此,也具有高延迟 . 如果负载水平上升 - 所有请求都是时间 .

WebClient用法:

@RestController
public class NonBlockingClientController {
private WebClient client = WebClient.create("http://localhost:9000");

@GetMapping("/client")
public Mono<String> getData() {
    return client.get()
            .uri("/routing")
            .accept(TEXT_PLAIN)
            .exchange()
            .then(response -> response.bodyToMono(String.class));
}
}

我不知道出了什么问题或当前的快照版本只是工作 .

所有来源发表于https://github.com/rutkowskij/blocking-non-blocking-poc

  • blocking-service - 缓慢阻塞 endpoints

  • 非阻塞客户端 - 基于Spring Boot 2.0和WebClient的客户端

我刚刚使用spring-boot-starter-webflux和版本2.0.0.BUILD-SNAPSHOT创建了一个简单的Spring Boot应用程序,它带来了spring-webflux版本5.0.0.BUILD-SNAPSHOT和Spring Core,Beans,Context等相同 .

1 回答

  • 7

    5.0 RC4发布后问题不再存在 . 该问题与reactor-netty和reactor-core中的连接池有关 .

    我也用Spring Boot 2.0.0.M4进行了测试 - 现在一切都很好看 .

    详情:http://jira.spring.io/browse/SPR-15584

相关问题