From 4b73c14ba75d8cfbbff8602a0f3af9dc289e16b5 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sun, 8 Nov 2015 20:42:01 -0800 Subject: [PATCH] Disable fastpath for hot reads The idea was that the hottest entries don't need to be reordered on reads, due to already being in a desirable state. Based on the power law, this would avoid unnecessary work for the majority of reads. When the hot entries are demoted, due to colder entries being promoted, the fast path wouldn't apply and it would regain its status. Thus little impact to the hit rate for faster throughput. Unfortunately benchmarks show otherwise. The throughput varies wildly and is always lower. This might be due to some type of thrashing in the CPU caches, but I'm really not sure. So its turned off but can be enabled in the future if a solution is found. --- .../benmanes/caffeine/cache/LocalCacheSelectorCode.java | 3 ++- .../com/github/benmanes/caffeine/cache/BoundedLocalCache.java | 4 +++- .../github/benmanes/caffeine/cache/BoundedLocalCacheTest.java | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheSelectorCode.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheSelectorCode.java index 33e48a050a..dee194119e 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheSelectorCode.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheSelectorCode.java @@ -102,7 +102,8 @@ private LocalCacheSelectorCode expires() { private LocalCacheSelectorCode fastpath() { block.beginControlFlow("if (fastpath)") - .addStatement("sb.append('F')") + .addStatement("// disabled due to unfavorable benchmarks") + .addStatement("// sb.append('F')") .endControlFlow(); return this; } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java index 2c1c7e5f80..78cc2f4dd0 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java @@ -787,7 +787,9 @@ void afterRead(Node node, long now, boolean recordHit) { } node.setAccessTime(now); - boolean delayable = canFastpath(node) || (readBuffer.offer(node) != Buffer.FULL); + // fastpath is disabled due to unfavorable benchmarks + // boolean delayable = canFastpath(node) || (readBuffer.offer(node) != Buffer.FULL); + boolean delayable = (readBuffer.offer(node) != Buffer.FULL); if (shouldDrainBuffers(delayable)) { scheduleDrainBuffers(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java index a1dca436f7..4748ff864f 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java @@ -294,7 +294,7 @@ public void exceedsMaximumBufferSize_onWrite(Cache cache) { assertThat(localCache.writeQueue(), hasSize(0)); } - @Test(dataProvider = "caches") + @Test(enabled = false, dataProvider = "caches") @CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine, population = Population.PARTIAL, maximumSize = MaximumSize.FULL, weigher = {CacheWeigher.DEFAULT, CacheWeigher.TEN}, @@ -330,7 +330,7 @@ public void fastpath(Cache cache, CacheContext context) { assertThat(middle.getMoveCount(), is(initialMoveCount + 1)); } - @Test(dataProvider = "caches") + @Test(enabled = false, dataProvider = "caches") @CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine, population = Population.FULL, maximumSize = MaximumSize.FULL, weigher = CacheWeigher.DEFAULT, expireAfterAccess = Expire.DISABLED, expireAfterWrite = Expire.DISABLED,