【问题标题】:Deploying spring boot app to cloud foundry fails with JVM memory issue将 Spring Boot 应用程序部署到 Cloud Foundry 失败并出现 JVM 内存问题
【发布时间】:2019-05-08 09:00:27
【问题描述】:

将 Spring Boot 应用程序部署到 Pivotal Cloud Foundry 失败并出现以下错误。实例的限制设置为 2GB,然后设置为 4GB。本地应用程序以 2GB 堆大小正常启动。 应用程序在缓存管理器初始化期间失败。 知道可能是什么根本原因吗?不确定 terracotta 在云代工中扮演什么角色,还有什么需要寻找的?

 2019-05-07T19:24:53.39+0530 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
   2019-05-07T19:24:53.39+0530 [APP/PROC/WEB/0] OUT Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.ehcache.StateTransitionException: Cache '<name hidden>' creation in EhcacheManager failed.
....
 Caused by: java.lang.IllegalArgumentException: An attempt was made to allocate more off-heap memory than the JVM can allow. The limit on off-heap memory size is given by the -XX:MaxDirectMemorySize command (or equivalent).
   2019-05-07T19:15:13.15+0530 [APP/PROC/WEB/0] OUT     at org.terracotta.offheapstore.paging.UpfrontAllocatingPageSource.bufferAllocation(UpfrontAllocatingPageSource.java:564)
   2019-05-07T19:15:13.15+0530 [APP/PROC/WEB/0] OUT     at org.terracotta.offheapstore.paging.UpfrontAllocatingPageSource.lambda$allocateBackingBuffers$1(UpfrontAllocatingPageSource.java:513)
   2019-05-07T19:15:13.15+0530 [APP/PROC/WEB/0] OUT     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
   2019-05-07T19:15:13.15+0530 [APP/PROC/WEB/0] OUT     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
   2019-05-07T19:15:13.15+0530 [APP/PROC/WEB/0] OUT     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
   2019

编辑: 已修复,通过移除堆外 ehcache 配置:maxBytesLocalOffHeap

【问题讨论】:

    标签: jvm heap-memory cloud-foundry terracotta


    【解决方案1】:

    默认情况下,Java buildpack 将约束 JVM 的各种内存区域。这样做是为了确保您的 Java 应用程序不会超过容器的内存限制,否则会很糟糕,并会导致您的应用程序崩溃。

    您的应用正在尝试创建超出 Java buildpack 设置的限制的直接内存量。在我写这篇文章时,Java buildpack 正在设置-XX:MaxDirectMemorySize=10M

    要完成这项工作,您只需在 manifest.yml 或 cf set-env 中设置一个环境变量,称为 JAVA_OPTS 并且内容需要包含 -XX:MaxDirectMemorySize=XXM 其中 XX 是较大的值你想使用的。

    当您像这样调整内存设置时,Java buildpack 会看到,并会减小其他内存区域的大小以进行补偿。如果您尝试使用大量直接内存,这可能会导致您没有足够的内存用于其他区域。如果发生这种情况,您需要增加应用程序的总体内存限制。

    https://github.com/cloudfoundry/java-buildpack/blob/master/docs/jre-open_jdk_jre.md#java-options

    希望有帮助!

    【讨论】:

    • 感谢 Daniel 的解释,我的 ehcache 堆外内存设置不是必需的,所以我删除了它们,问题消失了,但很高兴了解背景
    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 2012-03-24
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2020-03-05
    • 2012-04-10
    相关资源
    最近更新 更多