What diagnostic evidence should every production JVM in your fleet record continuously, and what overhead budget would you accept for it?
answer
- evidence before the incident
- unified logging, rotated
- a continuous low-overhead recording
- histograms per route and dependency
- CPU, disk and secrets
basics
~20 sKeep rotated GC and safepoint logs, a continuous JFR recording on its default settings bounded on disk, and latency histograms per route and dependency: about one to two percent of CPU and a fixed disk slice, with heavier tools only during incidents.
solid answer
~40 sThe first incident is the one you cannot reproduce, so the evidence must exist before it. My baseline is unified logging with `-Xlog:gc*,safepoint` to a rotated file; a continuous JFR recording started with `-XX:StartFlightRecording` on the `default` settings, which JDK 25 describes as typically under 1 % overhead, bounded with `maxage` or `maxsize` and pulled with `jcmd <pid> JFR.dump`; latency histograms per route and per downstream; and container CPU and throttling. I'd budget one to two percent of CPU, measured on a canary, and a fixed disk slice per instance, and pay more only on demand, such as the `profile` settings during an incident. The lead's real decisions are retention, where evidence lives after the pod dies, and who may read it, because recordings capture environment variables.
code
bash · 7 linesjava \
-Xlog:gc*,safepoint:file=/var/log/app/jvm-%p.log:time,uptime,level,tags:filecount=5,filesize=20m \
-XX:StartFlightRecording:settings=default,disk=true,maxage=6h,maxsize=500m,dumponexit=true,filename=/var/log/app/ \
-jar app.jar
# during an incident, write the buffered recording out without restarting
jcmd <pid> JFR.dump filename=/var/log/app/incident.jfrgo deeper
Recall that the JVM can log its garbage collections and safepoints and keep a Flight Recorder recording running, so evidence exists before anything goes wrong.
Explain how the baseline is configured: unified logging with rotation, a JFR recording started at launch on the default settings, bounded by age or size, and dumped with jcmd.
Show which incident questions each piece of always-on evidence answers, and what you add only during an incident, on the instance that misbehaves.
Own the trade: the CPU and disk budget, measured not assumed; retention sized to how far back reviews look; where evidence lives after a pod dies; and who may read recordings that capture configuration.
## Why the evidence must exist before the incident The first occurrence of a latency regression is usually the one you cannot reproduce: a peak that has passed, a downstream that recovered, a pod that was rescheduled. If the only way to find out what the JVM was doing is to turn diagnostics on afterwards, the first incident is always lost. So a lead sets a **standing baseline**: evidence every production JVM records continuously, cheap enough that nobody is tempted to switch it off, and bounded so it never threatens the service. This is a judgment call. There is no single right set; there is a trade between what the team can answer after the fact and what it pays in CPU, disk and data handling for every instance, all the time. ## A baseline set | Evidence | How it is recorded | What it answers later | Ongoing cost | |---|---|---|---| | GC and safepoint logs | `-Xlog:gc*,safepoint` to a rotated file | were there long stops, of what kind, when | very low; bounded disk | | Continuous JFR recording | `-XX:StartFlightRecording` with the `default` settings, kept on disk with `maxage` or `maxsize` | GC, safepoints, lock waits, socket I/O, CPU samples, container CPU and throttling, with stack traces | the JDK 25 `default.jfc` describes itself as typically under 1 % overhead; bounded disk | | Latency histograms | per route and per downstream dependency, exported as metrics | which requests got slower, and whether a dependency did | small, in the application | | Platform metrics | container CPU usage, throttling, memory, restarts | whether the JVM got the CPU it needed | outside the JVM | In JDK 25's `default` settings, for example, safepoint begin events are kept above 10 ms, monitor-blocked and park events above 20 ms, and socket reads and writes above 1 ms, all with stack traces, which is often enough to locate a regression without a second deploy. ## Bounding the cost - **CPU**: budget explicitly, for instance one to two percent per instance, and measure it on a canary rather than trusting a number from documentation. - **Disk**: rotation for logs (unified logging's file output rotates by `filecount` and `filesize`, by default 5 files of 20 MB) and `maxage` or `maxsize` for the JFR repository, sized against the pod's volume. - **Retrieval**: recordings and logs must survive the pod, so write them to a volume or ship them off the instance, and make `jcmd <pid> JFR.dump` part of the incident runbook. - **Consistency**: put the options in the base image or a shared launch script, so every service has the same evidence without opting in. ## What you pay for only during an incident The baseline is deliberately thin. Heavier instruments are reserved for the instance and the window that misbehave: - the JFR `profile` settings, which the JDK describes as typically around 2 % overhead and as meant for short periods; - a CPU, wall-clock, allocation or lock profile from async-profiler; - a series of thread dumps; - a heap dump, which stops the JVM for its duration and can be gigabytes, so it is a last resort on a latency problem. Whether a profiler should also run continuously, in which mode and at what overhead, is a separate decision with its own trade-offs. ## Governance a lead owns - **Sensitive content.** A JFR recording on the default settings captures the JVM's environment variables and system properties at the start of each chunk, plus stack traces and class names. Treat recordings like logs with sensitive data: restricted access and limited retention, and keep secrets out of environment variables and command-line options. - **Retention.** Decide how far back an incident review may need to look, and size the bounds to that, not to whatever fits. - **Who may change it.** Teams should not quietly switch the baseline off to win back a percent; exceptions are a reviewed decision. ## Deciding the budget 1. List the questions on-call must be able to answer after the fact: were there stops, was the JVM throttled, which route and which dependency, where did threads wait. 2. Map each to the cheapest always-on evidence that answers it. 3. Measure the combined overhead on a canary at peak load. 4. Bound disk and retention, decide where the evidence lives after the pod is gone, and decide who can read it. 5. Revisit after each incident: add what was missing, remove what nobody used.
- Why not run JFR's profile settings everywhere, since about 2 % is still small?Across a fleet a percent is real capacity, and the profile settings record more events at lower thresholds, so disk volume grows too; the JDK describes them as meant for short periods. The default settings already keep safepoints over 10 ms, monitor waits over 20 ms and socket I/O over 1 ms with stack traces. Start a profile recording with jcmd on the instances that misbehave.
- What should the policy say about who can pull recordings?A recording on the default settings holds stack traces, class names, system properties and the environment variables seen at the start of each chunk, which can include secrets or personal data passed as configuration. Treat recordings like sensitive logs: restricted access, limited retention, and keep secrets out of environment variables and command-line options.
- Turns diagnostics on only after the incident has started.
- Keeps JFR off because it used to be a commercial feature.
- Writes GC logs inside the container, lost when the pod restarts.
- Runs the profile settings everywhere without measuring their cost.
- Shares recordings freely without considering the secrets they hold.
Assumes JDK 25: the overhead figures and event thresholds quoted are those in JDK 25's bundled default.jfc and profile.jfc settings files.