2

Our app server, OpenLiberty, supports config defaults and overrides as defined at https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html#jvm-options

Options are read and provided to the JVM in order. If you provide multiple options, then they are all seen by the JVM.

Currently, we're setting an initial min heap size for our server (via configDropins/defaults/jvm.options). I'd like it to be possible to override that min heap size with the JVM's default (as if -Xms was never specified).

I confirmed that I can pass a new value to -Xms via configDropins/overrides, but what I'd really like to do is somehow override the initial setting so that it takes the JVM default (instead of a different custom value). I tried setting -Xms (with no value) in the override, but it seems to just use the value from configDropins/defaults.

There is a good related question at Duplicated Java runtime options : what is the order of preference? wrt how common JVMs handles duplicate options and a choice exceprt from one of the answers:

there are often deeply nested command lines from batch files where people can only add to the end, and want to make that the winner.

This makes me hope that maybe I'm not alone in wanting this feature. Does anyone know if there's already some way to achieve it?

lmsurprenant
  • 1,723
  • 2
  • 14
  • 28
  • So why you just not remove that setting from jvm.options, or set -Xms to the given jvm default manually (overriding your setting)? – Gas Oct 06 '21 at 11:26
  • We publish a docker image with this default. Users can certainly extend this image (or add a run script/postStart script) to edit/remove the default jvm.options file, but I'd like it to be more simple. The jvm default is actually quite sophisticated...its not a fixed value. – lmsurprenant Oct 06 '21 at 11:54
  • "what I'd really like to do is somehow override the initial setting" "but I'd like it to be more simple." If I'm reading you correctly, you want the user to be able to revert the docker image to jvm default for heap, but what would you consider simpler than a script to remove the value? – F Rowe Oct 06 '21 at 13:50
  • 1
    What about constructing your image entrypoint/command using the JVM_ARGS shell var to hold jvm options? You could script that in terms of some other env var which the user could override or unset, etc. – Scott Kurz Oct 06 '21 at 14:36
  • "you want the user to be able to revert the docker image to jvm default for heap" yeah, that was the hope. but after looking at it some more, I guess that the initial heap size defaults aren't as sophisticated as the max heap size one, so its probably ok for us to set a fixed size default and they can just override with a different default via a dropin (if they want). – lmsurprenant Oct 06 '21 at 19:13

1 Answers1

0

To be honest, you should not set heap sizes, when running in containers. Since Java8 there is built in support via UseContainerSupport setting which adjusts available heap size based on the container memory limits.

If you want to fine tune that you could use -XX:MaxRAMPercentage / -XX:InitialRAMPercentage settings.

This allows you to change heap sizes in more dynamic way, without the need of rebuilding the image.

Update
Based on https://www.ibm.com/docs/en/sdk-java-technology/8?topic=options-xxinitialrampercentage InitialRAMPercentage is kind of -Xms equivalent:

-XX:InitialRAMPercentage=N  Set initial heap size as a percentage of total memory  

Note: 
If you set a value for -Xms, the -XX:InitialRAMPercentage option is ignored. 
If you set a value for -Xmx, the -XX:MaxRAMPercentage option is ignored.
Gas
  • 17,601
  • 4
  • 46
  • 93
  • Yes, I've already removed our default `-Xmx` setting for just this reason. I don't think `UseContainerSupport` affects the `-Xms` value at all, but I could be mistaken. `XX:InitialRAMPercentage` could perhaps be of use here, I'll need to think about that. – lmsurprenant Oct 06 '21 at 19:10
  • @Imsurprenant if you manually set Xms/Xmx then you are not utilizing `UseContainerSupport` setting. – Gas Oct 06 '21 at 23:27
  • what does UseContainerSupport do for initial heap size? the openJ9 docs only mention max heap size and we've already removed that. my understanding is it is best practice to set a initial heap size to avoid needless memory management work for an app that we know needs a sizable heap (~512MiB). The docs say the default is 8MiB. – lmsurprenant Oct 07 '21 at 13:38