【问题标题】:what is wrong with below webclient config?下面的 webclient 配置有什么问题?
【发布时间】:2021-07-22 18:00:24
【问题描述】:

我面临连接错误。日志条目是 readAddress(..) 失败:连接被对等方重置;嵌套异常是 io.netty.channel.unix.Errors$NativeIoException: readAddress(..) failed: Connection reset by peer 连接发现错误 待定获取队列已达到其最大大小 1000;嵌套异常是 reactor.netty.internal.shaded.reactor.pool.PoolAcquirePendingLimitException

Webclient 配置为:

@Bean
public WebClient webClient(@Autowired ObjectMapperBean objectMapperBean) {
        ConnectionProvider provider =
                ConnectionProvider
                        .builder("custom")
                        .maxConnections(500)
                        .build();

        HttpClient httpClient = HttpClient.create(provider);

        ExchangeStrategies exchangeStrategies =
                ExchangeStrategies
                        .builder()
                        .codecs(codecConfigurer -> codecConfigurer
                                .defaultCodecs()
                                .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapperBean.getObjectMapper(), MediaType.APPLICATION_JSON)))
                        .build();

        return WebClient
                .builder()
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .exchangeStrategies(exchangeStrategies)
                .build();
    }

我不确定问题出在哪里。有人可以帮我吗? #springboot #webclient

【问题讨论】:

  • 您告诉您的网络客户端它最多只能有 500 个连接,并且“待定”连接队列(我认为默认情况下是双倍的)空间不足。您要么需要增加这个大小,要么减少并发连接的数量,可能通过减少应用程序中flatMap() 调用的并发性和类似情况。

标签: spring-boot spring-webflux webclient reactor


【解决方案1】:

默认情况下,reactor netty 服务器允许的待处理队列请求数为

2 * 连接数

如果没有明确提供。您需要根据您的吞吐量预期来处理这些配置。您可以按如下方式修改此属性:

ConnectionProvider.builder(CONNECTION_NAME)
        .maxConnections(<MaxConnectionThreads>)
        .pendingAcquireTimeout(Duration.ofMillis(<PendingAcquireTimeout>))
        .pendingAcquireMaxCount(<maxCount>)
        .maxIdleTime(Duration.ofMillis(<MaxIdleTime>))
        .build();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-09
    • 2018-06-27
    • 1970-01-01
    • 2017-03-08
    相关资源
    最近更新 更多