Video in progress
Your company has 60 Java services and every team sets JVM flags its own way. How do you standardize this?
I provide a common base image with good defaults (a container-friendly heap percentage, GC log, a dump on OOM, JFR). Teams change only what is allowed and documented, and changes come with evidence.
📖 Answer
At one company I saw this picture: half the services had -XX:+UseConcMarkSweepGC left over from 2015 (removed in JDK 14), someone had set -Xmx equal to the container limit, and some had no GC log at all. During an incident, you can't check anything.
What I do:
- A platform base image. One JDK distribution and version, with the defaults in
JAVA_TOOL_OPTIONSor in the entrypoint script:
-XX:MaxRAMPercentage=70 -XX:+ExitOnOutOfMemoryError
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps
-Xlog:gc*:file=/logs/gc.log:time,uptime:filecount=5,filesize=20m
-XX:StartFlightRecording=disk=true,maxage=6h,settings=default
-
Two layers. The platform defaults and the teams' overrides are in separate variables (
JAVA_OPTS_EXTRA). That way you can see who changed what. -
Lint. A simple rule in CI that checks Dockerfiles and Helm charts: a list of forbidden flags (obsolete GCs,
-Xmxlarger than the limit,-XX:+DisableExplicitGCwithout a reason). -
A dashboard. The same metrics from all services: GC pause p99, heap after GC, allocation rate. With a common log format, this is easy to collect.
The trade-off: centralization cuts into teams' freedom. That is why I like the rule "the defaults aren't mandatory, but if you change them, write the reason and the measurement in the PR". The hardest part isn't the technical side but updating the JDK version across all services at the same time. That has to be done step by step with a new tag of the base image and automatic PRs (like Renovate).
Sign up to mark studied questions and save your progress.