简体   繁体   English

Java 17 应用程序在 docker 中显示非常高的 RAM 使用率

[英]Java 17 app shows very high RAM usage in docker

I have a application that during idle times usually only needs 1GB of RAM however when I launch it inside in docker, then it shows much higher RAM usage (5GB) from the outside.我有一个应用程序,在空闲时间通常只需要 1GB 的 RAM,但是当我在 docker 内部启动它时,它从外部显示出更高的 RAM 使用率(5GB)。 The JVM metric show that I still only use ~1GB of RAM, but the JVM does not really release any RAM it ever claimed. JVM 指标显示我仍然只使用约 1GB 的 RAM,但 JVM 并没有真正释放它声称的任何 RAM。 I cannot reduce the RAM limits (~8GB using MaxRamPercentage), as it needs it during high load, startup, and some special events.我无法减少 RAM 限制(使用 MaxRamPercentage 约 8GB),因为它在高负载、启动和一些特殊事件期间需要它。 I could periodically call System.gc() as that frees and releases a lot of memory, but the RAM shoots back up to where it was after a few requests.我可以定期调用System.gc() ,因为它会释放并释放大量 memory,但 RAM 在几次请求后会恢复到原来的位置。 This claiming of unused RAM wastes a lot of resources and causes OOMs on the server as none of the applications release their memory.这种声称未使用 RAM 会浪费大量资源并导致服务器上出现 OOM,因为没有任何应用程序发布其 memory。

According to this JEP-346 the "bug" has been fixed, that caused the garbage collector to not release the memory, but I don't see any improvements.根据this JEP-346 ,“错误”已修复,导致垃圾收集器不释放memory,但我没有看到任何改进。

For testing purposes, I also tried using the -XX:+UseShenandoahGC and it releases the memory as expected.出于测试目的,我还尝试使用-XX:+UseShenandoahGC并按预期释放 memory。 But during startup it takes almost all the RAM which causes issues during server/multiple simultaneous application restarts.但是在启动过程中,它几乎占用了所有 RAM,这会在服务器/多个同时应用程序重新启动期间导致问题。

TLDR: Actually used RAM ~1 GB, claimed RAM ~5 GB, RAM Limit ~8GB. TLDR:实际使用的 RAM ~1 GB,声称的 RAM ~5 GB,RAM 限制 ~8GB。 The default GC does not release enough RAM, without explicitly calling System.gc().默认 GC 不会释放足够的 RAM,没有显式调用 System.gc()。 Is the G1 GC the default GC in Java 17? G1 GC是Java 17中的默认GC吗? (AFAICT it is) Are there any parameters required to make the changes from JEP-346 work as expected? (AFAICT 是)是否需要任何参数才能使JEP-346的更改按预期工作?

I think this is similar question to what you are asking .我认为这与您所问的问题相似

As it is pointed in the comments to the question this feature is opt-in and can be enabled using parameters described in the JEP 346 Documentation .正如对问题的评论中指出的那样,此功能是可选的,可以使用JEP 346 文档中描述的参数启用。

Both -XX:G1PeriodicGCInterval and -XX:G1PeriodicGCSystemLoadThreshold have to be set to a value greater than default 0 for the functionality to work. -XX:G1PeriodicGCInterval-XX:G1PeriodicGCSystemLoadThreshold都必须设置为大于默认值 0 的值才能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM