Improve default handling of JVM heap size

Description

Modify CommandBox to not set a max or min heap size if none is provided by the user.

Also allow heap size to have the k, m, or g identifier.

Default if no letter is provided will still be "m"

Original ticket


Per the thread of CFML slack referencing this article:

https://medium.com/@yortuc/jvm-memory-allocation-in-docker-container-a26bbce3a3f2

Commandbox specifies a default heapSize of 512 in /src/cfml/system/services/ServerService.cfc:127. In a Docker deployment, it appears that the best practice is not to specify a heap size at all. But it's probably not a good idea to just remove this value for everyone, so perhaps a transitional argument and environment variable that, when set, removes any default values for heapSize?

It could be simplified further, depending on how prescriptive you want to be, by directly adding the relevant JVM arguments, e.g. if

CFML_JVM_DOCKERHEAPMODE = 1

then no default heapSize, and the follow JVM args get added:

This is the first time I've plumbed into the Commandbox source and it looks pretty straightforward, but I'm not quite comfortable enough yet to deal with optional settings that could come from either the command line or the environment (and not sure if that's Commandbox proper or just the Docker stuff).

Activity

Show:

Brad Wood November 24, 2018 at 4:14 AM
Edited

Looks like those experiemental args have already been phased out in newer versions of Java
https://blog.csanchez.org/2018/06/21/running-a-jvm-in-a-container-without-getting-killed-ii/

I'm not sure it makes sense to force a max size since the JVM is already pretty good about not taking more than the OS has to offer. Based on the article above, Java 10 already has some built-in Docker support too to detect the amount of RAM in the container.

Since the Java args and sort of in flux right now, I've just removed the default max size entirely. Users wanting that back can do this:

For users wanting to use the experimental JVM args in java 8, they can leave the JSON file empty in regards for heap sizes, and then manually add whatever JVM args make sense for them and their version of Java.

Also, while I was in there, I made an improvement that I've wanted to do for a while. If you leave off the letter, then CommandBox assumes you mean MB for the heap size, but you can also add "m" or "G" which is a bit cleaner for large heap sizes now.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Labels

Fix versions

Priority

Sentry

Created November 6, 2018 at 1:52 PM
Updated November 24, 2018 at 4:18 AM
Resolved November 24, 2018 at 4:18 AM