Search code examples
javacloud-foundrybuildpack

cloudfoundry java buildpack memory changes not reflecting


I want to make changes in memory settings for my java apps in cloudfoundry java-buildpack. I have tried these two ways:

  1. Using JBP_CONFIG_OPEN_JDK_JRE paramter in my manifest.yml. As suggested in https://github.com/cloudfoundry/java-buildpack-memory-calculator
  2. Making this change in config\open_jdk_jre.yml:

memory_calculator:
version: 3.8.0_RELEASE
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}" stack_threads: 300
memory_sizes:
stack: 2M
metaspace: 160M
heap: 900M

However, none of this is getting reflected while deployment of my apps. I am using latest java-buildpack.


Solution

  • This depends on the version of the Java build pack that you're using.

    Version 3.x

    For versions 3.x, you would set an env variable to configure the memory calculator. Like here.

    https://github.com/cloudfoundry/java-buildpack/tree/3.x#configuration-and-extension

    Ex:

    cf set-env my-application JBP_CONFIG_OPEN_JDK_JRE '{ memory_calculator: { memory_heuristics: { heap: 85, stack: 10 } } }'
    

    This will then override the memory heuristics configuration that defaults in the build pack, specifically the heap and stack weights.

    A few notes:

    • Understanding what the different memory configuration options do is another matter. You can read about those here.
    • This is only for OpenJDK, if you're using a different JDK then the configuration options are slightly different. Ex: JBP_CONFIG_ORACLE_JRE for Oracle. The name mirrors the config file path & name.
    • It doesn't matter how you set the env variable for your app. You can use cf set-env like above or you can set the env variable in your manifest.yml file. Both work just fine.

    Version 4.x

    In version 4.x, the configuration of the JVM's memory settings has gotten a lot simpler.

    however if you believe that your application doesn’t need these JVM defaults, you can now configure those memory regions directly with JVM options.

    https://www.cloudfoundry.org/just-released-java-buildpack-4-0/

    What this means is you still configure the JVM settings through an env variable, but you only need to set JAVA_OPTS and you use the standard JVM configuration options.

    For example:

    cf set-env my-app JAVA_OPTS '-XX:ReservedCodeCacheSize=100M'
    

    You can set JAVA_OPTS in your manifest.yml, if you prefer doing that instead of running cf set-env.

    Hope that helps!