Webclient在Docker中泄漏内存?

乔乔

我正在尝试在项目中使用Webclient,但是在进行负载测试时,我注意到docker内存使用量永远不会下降,直到实例死亡。

@Component
public class Controller {

  //This is an endpoint to another simple api
  //I use my local Ip instead of localhost in the container
  private static final String ENDPOINT = "http://localhost:9090/";

  private WebClient client;
  
  public Controller(WebClient.Builder client) {
    super();
    this.client = client.build();
  }

  @Bean
  public RouterFunction<ServerResponse> router() {

    return RouterFunctions.route(GET("helloworld"), this::handle);
  }

  Mono<ServerResponse> handle(ServerRequest request) {

    Mono<String> helloMono =
        client.get().uri(ENDPOINT + "/hello").retrieve().bodyToMono(String.class);

    Mono<String> worldMono =
        client.get().uri(ENDPOINT + "/world").retrieve().bodyToMono(String.class);

    return Mono.zip(helloMono, worldMono, (h, w) -> h + w)
        .flatMap(s -> ServerResponse.ok().bodyValue(s));
  }
}

这也是我的dockerFile。

FROM openjdk:8

ENV SERVICE_NAME reactive-hello-world

ADD target/reactive-hello-world-*.jar $APP_HOME/reactive-hello-world.jar

RUN mkdir /opt/reactor-netty/


EXPOSE 9010

CMD java \
    -Dcom.sun.management.jmxremote=true \
    -Dcom.sun.management.jmxremote.local.only=false \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Djava.rmi.server.hostname=localhost \
    -Dcom.sun.management.jmxremote.port=9010 \
    -Dcom.sun.management.jmxremote.rmi.port=9010 \ 
    -Xmx190M \
    -jar reactive-hello-world.jar

EXPOSE 8080

我在某处错过了一步吗?

编辑:这是一些图片

负载测试之前: 负载测试前

负载测试后

在此处输入图片说明

如您所见,GC正常运行,但内存并未减少。如果我继续进行测试,它将在几分钟内杀死该实例。

我已经尝试过使用类似的代码RestTemplate,但没有遇到任何问题,即使我长时间运行Jmeter,内存通常也不会超过400MB。您能帮助您了解发生了什么吗?

编辑:我也尝试过时AsyncRestTemplate,我也没有看到任何问题。

编辑:我已经为这个例子创建了仓库。请检查是否可以重现该问题。

你好世界后端

Webclient Hello World(此存储库中包含JMX)

RestTemplate Hello World

AsyncRestTemplate Hello World

乔乔

没关系的小伙子们,我能够找到答案,请参阅:

https://github.com/reactor/reactor-netty/issues/1304

从本质上讲,反应堆对净值的依赖已经过时了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章