[ 
https://issues.apache.org/jira/browse/OAK-12378?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Nuno Santos resolved OAK-12378.
-------------------------------
    Fix Version/s: 2.8.0
       Resolution: Fixed

> PropertyTemplate.compareTo() allocates a new Comparator chain on every call, 
> dominating GC pressure during full compaction
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OAK-12378
>                 URL: https://issues.apache.org/jira/browse/OAK-12378
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: segment-tar
>            Reporter: Nuno Santos
>            Priority: Major
>             Fix For: 2.8.0
>
>
> h2. Summary
> {{PropertyTemplate.compareTo()}} in oak-segment-tar builds a brand-new 
> {{Comparator}} chain (3 allocated objects: {{comparingInt}} + two 
> {{thenComparing}} wrappers) on {*}every single pairwise comparison{*}, 
> instead of building it once and reusing it.
> {code:java}
> // 
> oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/PropertyTemplate.java:74-81
> @Override
> public int compareTo(@NotNull PropertyTemplate template) {
>     requireNonNull(template);
>     return Comparator.comparingInt(PropertyTemplate::hashCode)
>             .thenComparing(PropertyTemplate::getName)
>             .thenComparing(PropertyTemplate::getType)
>             .compare(this, template);
> }
> {code}
> This method is invoked by 
> {{{}ComparableTimSort{}}}/{{{}Arrays.sort(Object[]){}}} inside 
> {{Template.<init>(SegmentReader, NodeState)}} — i.e. O(n log n) times for 
> every {{Template}} constructed. A {{Template}} is built for every node 
> written 
> ({{{}DefaultSegmentWriter$SegmentWriteOperation.writeNode(Uncached){}}}), so 
> this fires constantly during normal writes and especially during full/online 
> compaction, where huge numbers of nodes are rewritten in a short window.
> h2. Evidence
> Found while analyzing a JFR recording taken during compaction. The top 
> allocation is the {{Comparator}} lambda instance, being responsible for *~81% 
> of all sampled allocation weight* (~705 GB estimated pressure from 1,067 
> samples), dwarfing every other allocation site in the recording (next highest 
> was ~3.5%). Nearly all samples share the identical stack:
> {code:java}
> jdk.internal.misc.Unsafe.allocateInstance(Class)
> java.lang.invoke.DirectMethodHandle.allocateInstance(Object)
> java.util.Comparator.comparingInt(ToIntFunction)
> org.apache.jackrabbit.oak.segment.PropertyTemplate.compareTo(PropertyTemplate)
>  line: 77
> org.apache.jackrabbit.oak.segment.PropertyTemplate.compareTo(Object) line: 35
> java.util.ComparableTimSort.binarySort/sort(...)
> java.util.Arrays.sort(Object[])
> org.apache.jackrabbit.oak.segment.Template.<init>(SegmentReader, NodeState) 
> line: 134
> org.apache.jackrabbit.oak.segment.DefaultSegmentWriter$SegmentWriteOperation.writeNodeUncached/writeNode
> {code}
> The same recording shows the JVM (1.2 GB heap) under heavy GC stress during 
> compaction: 77 old-gen GCs totaling 41.2s of the 300s window (13.7%), 200 
> {{EvacuationFailed}} events, and 4 {{ConcurrentModeFailure}} events (G1 
> to-space exhaustion falling back to full GC). This allocation site is a 
> strong candidate for the primary driver of that garbage volume.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to