2

I am using below parameters to override my heap config for JVM -

JBP_CONFIG_OPEN_JDK_JRE: '[memory_calculator: {memory_heuristics: {heap: 65, metaspace: 20}}]'

But I am not able to see the changes getting reflected. Can someone help?

trincot
  • 317,000
  • 35
  • 244
  • 286
Ankita Gupta
  • 33
  • 1
  • 3

1 Answers1

1

The options you're using only apply for version 3.x of the Java buildpack.

Starting with Java buildpack 4, all you need to do is to set JAVA_OPTS with your JVM configuration options. So if you want to override the max heap size and change the thread stack size, you can do cf set-env my-app JAVA_OPTS '-Xmx100m -Xss228k'.

The Java buildpack will read these values and attempt to adjust the other areas of memory used by the JVM so that it can accommodate running your app within the defined memory limit. If it cannot do that, the Java buildpack will print an error telling you this.

For example, if you set the memory limit to 512M and you set a max heap of 500M, that's not going to work. There won't be enough memory left for other areas of the JVM and the JBP will reject your settings. This is a safety check so to keep your application from exceeding the memory limit and crashing at some point in the future.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • Thank you @Daniel Mikusa. If I have to increase metaspace, will this work? `cf set-env my-application JAVA_OPTS '-XX:MaxMetaspaceSize=257586K' ` from current value 128793K. Thanks, – Chandan Patra Oct 18 '18 at 18:22
  • Tried: `cf set-env my-application JAVA_OPTS '-XX:MaxMetaspaceSize=257586K' ` I tried that, but my log output doesn't confirm the same: ` [OUT] JVM Memory Configuration: -Xmx278990K -Xss1M -XX:ReservedCodeCacheSize=240M -XX:MaxDirectMemorySize=10M` Without setting the metaspacesize, the log was : `[OUT] JVM Memory Configuration: -Xmx407782K -Xss1M -XX:ReservedCodeCacheSize=240M -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=128793K` Thanks, Chandan – Chandan Patra Oct 18 '18 at 18:32
  • It should work for any JVM memory settings, including `-XX:MaxMetaspaceSize`. Confirm that you set JAVA_OPTS correctly, run `cf env my-app` and see that it contains `-XX:MaxMetaspaceSize`. Also, make sure you're restaging. You have to restage for these changes to take effect. – Daniel Mikusa Oct 18 '18 at 19:14
  • Hi Daniel, `cf env MY_APP` does not show the JVM properties set for the app. I did both restage and restart. The JAVA_OPTS shows in `User Provided Environment Variables` which is correctly set. I wonder if `memory_calculator` honors `XX:MaxMetaspaceSize`. Thanks, – Chandan Patra Oct 18 '18 at 19:58
  • Memory calculator definitely takes into account `-XX:MaxMetaspaceSize`. The only other reason I could think it might not work is if you're using a really old version of the JBP. You need to be at least into the 4.x branch. If you still on 3.x, this won't work. You shouldn't be using 3.x any more, it's pretty old at this point and it lacks certain fixes which can cause Java apps deployed by it to crash more often. – Daniel Mikusa Oct 19 '18 at 12:33