OAK-12210 : added benchmark for segment cache with cachelirs, caffein…#2898
OAK-12210 : added benchmark for segment cache with cachelirs, caffein…#2898rishabhdaim wants to merge 15 commits into
Conversation
|
Result is :
--- Scenario D: uniform random / cache thrash (pool=25,000 = ~25x cache measure=200,000 ops) ---
So caffeine is efficient than Guava/CacheLIRS is all scenarios. |
|
|
|
Can you try the ones added here: https://github.com/ChlineSaurus/jackrabbit-oak/tree/mw/pr-2898-tmg-repro |
|
not sure if it helps, but I have a list of traces where these are my favorites as they show a variety of scenarios. I added a patch and examples if you want to play with it. jackrabbit.patchdiff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts
index 3083461cf..8c92fb767 100644
--- a/simulator/build.gradle.kts
+++ b/simulator/build.gradle.kts
@@ -26,6 +26,7 @@ dependencies {
implementation(libs.ehcache3)
implementation(libs.fastutil)
implementation(libs.hazelcast)
+ implementation(libs.jackrabbit)
implementation(libs.jfreechart)
implementation(libs.fast.filter)
implementation(libs.ascii.table)
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java
index 54d620e84..fe12a6a51 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java
@@ -61,6 +61,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.product.Ehcache3Polic
import com.github.benmanes.caffeine.cache.simulator.policy.product.ExpiringMapPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.product.GuavaPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.product.HazelcastPolicy;
+import com.github.benmanes.caffeine.cache.simulator.policy.product.JackrabbitLirsPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.product.TCachePolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.sampled.SampledPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.sketch.WindowTinyLfuPolicy;
@@ -232,6 +233,7 @@ public final class Registry {
registerMany(TCachePolicy.class, TCachePolicy::policies);
registerMany(CoherencePolicy.class, CoherencePolicy::policies);
registerMany(HazelcastPolicy.class, HazelcastPolicy::policies);
+ register(JackrabbitLirsPolicy.class, JackrabbitLirsPolicy::new);
registerMany(ExpiringMapPolicy.class, ExpiringMapPolicy::policies);
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/JackrabbitLirsPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/JackrabbitLirsPolicy.java
new file mode 100644
index 000000000..afb05f01c
--- /dev/null
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/JackrabbitLirsPolicy.java
@@ -0,0 +1,59 @@
+package com.github.benmanes.caffeine.cache.simulator.policy.product;
+
+import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED;
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.Set;
+
+import org.apache.jackrabbit.oak.cache.CacheLIRS;
+
+import com.github.benmanes.caffeine.cache.simulator.BasicSettings;
+import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent;
+import com.github.benmanes.caffeine.cache.simulator.policy.Policy;
+import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec;
+import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
+import com.typesafe.config.Config;
+
+@PolicySpec(name = "product.JackrabbitLirs", characteristics = WEIGHTED)
+public final class JackrabbitLirsPolicy implements Policy {
+ private final CacheLIRS<Long, AccessEvent> cache;
+ private final PolicyStats policyStats;
+
+ public JackrabbitLirsPolicy(Config config, Set<Characteristic> characteristics) {
+ var settings = new BasicSettings(config);
+ this.policyStats = new PolicyStats(name());
+ var builder = CacheLIRS.<Long, AccessEvent>newBuilder()
+ .evictionCallback((_, _, _) -> policyStats.recordEviction())
+ .recordStats();
+ if (characteristics.contains(WEIGHTED)) {
+ builder.maximumWeight(settings.maximumSize());
+ builder.weigher((Long _, AccessEvent value) -> value.weight());
+ } else {
+ builder.maximumSize(settings.maximumSize());
+ }
+ this.cache = builder.build();
+ }
+
+ @Override
+ public void record(AccessEvent event) {
+ Object value = cache.getUnchecked(event.longKey());
+ if (value == null) {
+ cache.put(event.longKey(), event);
+ policyStats.recordMiss();
+ } else {
+ policyStats.recordHit();
+ }
+ }
+
+ @Override
+ public PolicyStats stats() {
+ return policyStats;
+ }
+
+ @Override
+ public void finished() {
+ var stats = cache.stats();
+ checkState(policyStats.hitCount() == stats.hitCount());
+ checkState(policyStats.missCount() == stats.missCount());
+ }
+}
diff --git a/simulator/src/main/resources/reference.conf b/simulator/src/main/resources/reference.conf
index 427efa526..fc854adcd 100644
--- a/simulator/src/main/resources/reference.conf
+++ b/simulator/src/main/resources/reference.conf
@@ -107,6 +107,7 @@ caffeine.simulator {
product.Coherence,
product.Hazelcast,
product.ExpiringMap,
+ product.JackrabbitLirs,
]
# The admission policy (opposite of eviction policy)SQL Database./gradlew simulator:simulate \
--maximumSize=1_000_000,2_000_000,3_000_000,4_000_000,5_000_000,6_000_000,7_000_000,8_000_000 \
-Dcaffeine.simulator.files.paths.0="arc:/Users/ben/Documents/traces/arc/DS1.lis.xz" \
-Dcaffeine.simulator.policies.0="product.JackrabbitLirs" \
-Dcaffeine.simulator.policies.1="product.Caffeine" \
-Dcaffeine.simulator.policies.2="product.Guava" \
-Dcaffeine.simulator.policies.3="irr.Lirs" \
-Dcaffeine.simulator.policies.4="opt.Clairvoyant" \
--title="Database" -PjvmArgs=-Xmx12g
Stress test./gradlew simulator:run -q \
-Dcaffeine.simulator.policies.0="product.JackrabbitLirs" \
-Dcaffeine.simulator.policies.1="product.Caffeine" \
-Dcaffeine.simulator.policies.2="product.Guava" \
-Dcaffeine.simulator.policies.3="irr.Lirs" \
-Dcaffeine.simulator.policies.4="opt.Clairvoyant" \
-Dcaffeine.simulator.files.paths.0="corda:trace_vaultservice_large.gz" \
-Dcaffeine.simulator.files.paths.1="lirs:loop.trace.gz" \
-Dcaffeine.simulator.files.paths.2="lirs:loop.trace.gz" \
-Dcaffeine.simulator.files.paths.3="lirs:loop.trace.gz" \
-Dcaffeine.simulator.files.paths.4="lirs:loop.trace.gz" \
-Dcaffeine.simulator.files.paths.5="lirs:loop.trace.gz" \
-Dcaffeine.simulator.files.paths.6="corda:trace_vaultservice_large.gz"
╔════════════════════════╤══════════╤═══════════╤═══════════╤═══════════╤═══════════╤════════════╤═══════════╤══════════╗
║ Policy │ Hit Rate │ Miss Rate │ Hits │ Misses │ Requests │ Evictions │ Steps │ Time ║
╠════════════════════════╪══════════╪═══════════╪═══════════╪═══════════╪═══════════╪════════════╪═══════════╪══════════╣
║ irr.Lirs │ 20.16 % │ 79.84 % │ 1,264,261 │ 5,007,883 │ 6,272,144 │ 5,007,371 │ 8,782,107 │ 451.6 ms ║
╟────────────────────────┼──────────┼───────────┼───────────┼───────────┼───────────┼────────────┼───────────┼──────────╢
║ opt.Clairvoyant │ 40.30 % │ 59.70 % │ 2,527,704 │ 3,744,440 │ 6,272,144 │ 3,743,928 │ │ 1.7 s ║
╟────────────────────────┼──────────┼───────────┼───────────┼───────────┼───────────┼────────────┼───────────┼──────────╢
║ product.Caffeine │ 38.51 % │ 61.49 % │ 2,415,227 │ 3,856,917 │ 6,272,144 │ 3,856,405 │ │ 1.2 s ║
╟────────────────────────┼──────────┼───────────┼───────────┼───────────┼───────────┼────────────┼───────────┼──────────╢
║ product.Guava │ 19.90 % │ 80.10 % │ 1,248,214 │ 5,023,930 │ 6,272,144 │ 5,023,418 │ │ 1.1 s ║
╟────────────────────────┼──────────┼───────────┼───────────┼───────────┼───────────┼────────────┼───────────┼──────────╢
║ product.JackrabbitLirs │ 0.48 % │ 99.52 % │ 29,838 │ 6,242,306 │ 6,272,144 │ 12,483,264 │ │ 1.1 s ║
╚════════════════════════╧══════════╧═══════════╧═══════════╧═══════════╧═══════════╧════════════╧═══════════╧══════════╝ |
|
Build is failing due to resource leakage in DocumentNodeStoreIT test. To be fixed by : #2905 |
955e703 to
126104d
Compare
…e & guava cache
JIRA-1: CaffeineCacheAdapter.invalidateAll() now calls cleanUp() so pending eviction notifications are flushed synchronously before the map is cleared, preventing stale weight in getCacheStats(). JIRA-3: SegmentCache.clear() resets the weight counter; recordHit() signature changed to recordHit(SegmentId) so L1 hits are propagated to L2 (FT_NOTIFY_L2_ON_L1_HIT toggle, default enabled), keeping W-TinyLFU frequency/LRU recency accurate for memoised segments. SegmentId.onAccess widened from Runnable to Consumer<SegmentId>. JIRA-5: PersistentDiskCache fixes for dirty-read and size accounting. JIRA-6: Benchmark warmup raised to 200K ops to saturate W-TinyLFU sketch to freq=15; SKIP_CACHE_CLEAR replaced by -Doak.benchmark.clearCacheOnCompaction toggle; scenario descriptions updated with measured freeze numbers and JIRA-4 fix reference. AbstractFileStore exposes clearSegmentCache() for benchmark use. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d GUAVA policy Two branches in SegmentCache were untested: - recordHit() path when FT_NOTIFY_L2_ON_L1_HIT is disabled (stats still counted) - newSegmentCache(long, GUAVA) path: GuavaCacheAdapter + buildGuavaCache Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…luting production code
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ce in same thread
|





…e & guava cache