Remix.run Logo
▲ hibikir an hour ago

While you are replying to someone that definitely knows this, you'd be surprised by the number of production containers out there, in big companies, that haven't turned on container support, or hand tuned their memory well, and thus end up throwing away large parts of the memory they are allocated.

Having used Java since the days where you needed to do very heavy tuning to get it to run properly, it all seems alien, as understanding the old garbage collectors was basically mandatory 20 year ago. But even if you reply to someone that does understand the new features, you might be helping a bunch of people that don't. In my unit of about 100 programmers I am the only one that even bothered looking, given how every single pod we deployed was either completely unconfigured, or so badly misconfigured, using settings that haven't been ideal since Java 6.

In one of the pods, running a batch job that was using way too much memory, about a third of the memory in the old generation were millions of copies of the very same string. Interning of strings loaded like that has been a JVM option since 2014.

▲gavinray 7 minutes ago | parent [-]

On that note, here's my favorite little-known tip for running Docker/Container JVM apps:

The Redhat image distros, like UBI and the JDK ones, have a really handy bash script, "run-java.sh". It's a wrapper script for best-practice and intelligent JVM runtime args inside of container envs:

  /opt/jboss/container/java/run/run-java.sh
It started life as fabric8's run-java-sh, and it's what the Dockerfile.jvm generated by Quarkus apps uses as its entrypoint.

The script handles, among other things:

- Heap sized as a percentage of the container's memory limit via -XX:MaxRAMPercentage (default 80%, compared with JVM's default of 25%). Tunalbe with JAVA_MAX_MEM_RATIO env.

- -XX:+ExitOnOutOfMemoryError, so an OOM kills the container and your orchestrator restarts it

- Defaults for GC and metaspace

- JAVA_DEBUG=true / JAVA_DEBUG_PORT=*:5005 turns on JDWP without you having to edit the Dockerfile

- http_proxy/https_proxy/no_proxy env vars get translated into -Dhttp.proxyHost etc