Video in progress
When you open a JFR recording in Mission Control, how do you analyze allocation pressure and lock contention?
For allocation I group the ObjectAllocationSample events by stack trace to find the places allocating the most bytes. For locks I sort the JavaMonitorEnter and ThreadPark events by monitor class and wait time.
📖 Answer
To make the recording useful for analysis, I take it with the profile settings:
jcmd $PID JFR.start name=diag settings=profile duration=5m filename=/tmp/diag.jfr
With the default settings some events have higher thresholds, and short lock waits may stay invisible.
Allocation. In JMC, the Memory page, or jdk.ObjectAllocationSample in the Event Browser. Each sample has a weight, which roughly says how many bytes were allocated. When I group by stack trace, usually 2-3 places account for half of all allocation. For example: a 64 KB StringBuilder on every request, reading JSON into a String and then parsing it again, needless boxing inside a stream().
Tie it to the allocation rate (MB/s) on the GC page: if you bring it below 2 GB/s, young GCs drop noticeably.
Lock contention.
jdk.JavaMonitorEnter: waiting on asynchronizedblock, with the monitor class and wait duration;jdk.ThreadPark: waiting onReentrantLock,CompletableFutureand pools.
I group by monitor class and look at the total wait time. Typical findings: a log appender, a synchronized singleton cache, or the DB connection pool.
You can also work without JMC:
jfr print --events jdk.JavaMonitorEnter /tmp/diag.jfr | less
jfr summary /tmp/diag.jfr
Sign up to mark studied questions and save your progress.