spring-boot - Webclient 在 Docker 中泄漏内存?

标签 spring-boot docker reactive-programming spring-webflux project-reactor

我正在尝试在我的项目中使用 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

我是不是漏掉了一步?

编辑:这是一些图片

负载测试前: Before load test

负载测试后

enter image description here

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

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

编辑:我也尝试过已弃用的 AsyncRestTemplate,但我也没有发现任何问题。

编辑:我已经为此示例创建了存储库。请检查您是否可以重现该问题。

The Hello World Backend

The Webclient Hello World (JMX 在这个 repo 中)

The RestTemplate Hello World

The AsyncRestTemplate Hello World

最佳答案

别介意小伙子们,我找到了答案,请参阅:

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

本质上,reactor netty 依赖已经过时了。

关于spring-boot - Webclient 在 Docker 中泄漏内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63458889/

相关文章:

java - Spring项目中的org.springframework.beans.NotWritablePropertyException

docker - 无法从Docker容器访问WSO2流处理器Studio服务

multithreading - RxJava 并行化是否打破了 Observable 契约?

java - DefaultJmsListenerContainerFactory - 并发 - 每个队列的线程数在什么时候开始增加?

spring - 按排名对结果进行排序

docker - 将 JIRA 从 native 实例恢复到 docker 容器

r - 带有nearPoints()的动态ggplot图层 Shiny

json - meteor `Deps.autorun` 与 `Collection.observe`

spring - ROLE_USER 和 ADMIN 对 URL 的访问限制

Python 在 Docker 容器中找不到文件