-
Notifications
You must be signed in to change notification settings - Fork 17
Description
we are seeing some of our java 21 spring-boot applications with an error message as
"Terminating due to java.lang.OutOfMemoryError: Metaspace"
When we checked the application logs on KOB, we saw the Loaded Class Count: 28339 and subsequently based on the JVM memory calculator they are assigning -XX:MaxMetaspaceSize=174185K for the application.
[sbil-asset-api-ge1-f665f55c5-xbbdp] Adding $JAVA_OPTS to $JAVA_TOOL_OPTIONS
[sbil-asset-api-ge1-f665f55c5-xbbdp] Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx1266938K -XX:MaxMetaspaceSize=174185K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 1953124K, Thread Count: 250, Loaded Class Count: 28339, Headroom: 0%)
[sbil-asset-api-ge1-f665f55c5-xbbdp] Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -Dspring.profiles.active=cloud,ge1,security-oauth2,master -Dinfo.version=26.0205.0-2502241229-373718fd -XX:MaxDirectMemorySize=10M -Xmx1266938K -XX:MaxMetaspaceSize=174185K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true
However, this metaspace is insufficient and the application crashes as soon as we receive load on the application.
For the same application deployed on PCF, it shows the Loaded Classes: 35530 and it has a higher -XX:MaxMetaspaceSize=219050K
2025-02-25T12:12:57.375+05:30 [STG/0] [OUT] [1m[31m----->[0m[22m Downloading [1m[34mOpen JDK Like Memory Calculator[0m[22m [34m3.13.0_RELEASE[0m from https://java-buildpack.cloudfoundry.org/memory-calculator/jammy/x86_64/memory-calculator-3.13.0-RELEASE.tar.gz [3m[32m(found in cache)[0m[23m
2025-02-25T12:12:58.321+05:30 [STG/0] [OUT] Loaded Classes: 35530, Threads: 250
Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -XX:MaxMetaspaceSize=219050K -Dspring.profiles.active=cloud,ge1,security-oauth2,master -Dinfo.version=26.0205.0-2502241229-373718fd -XX:MaxDirectMemorySize=10M -Xmx1222074K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true
So we tried to update the -XX:MaxMetaspaceSize=219050K through JAVA_OPTS variable for KOB application and it is working as expected. So we wanted to know how we can optimally manage the memory parameters rather than having to manually manage them for each of our micro services.