From 2b9775d5933feb95b539d32611fca94fe4b62c6e Mon Sep 17 00:00:00 2001 From: izeye Date: Mon, 15 Jun 2015 21:27:32 +0900 Subject: [PATCH 1/2] Fix EhCache hit/miss ratio The hitRatio is the ratio of two windowed rates that are calculated independently. They are not updated or read transactionally, hence the ratio of the two can drift slightly from what might be expected. We now make sure that the hit or miss ratio can't be higher than 1 Closes gh-3235 --- .../boot/actuate/cache/EhCacheStatisticsProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java index 6bfd671c668..98301e36295 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java @@ -37,8 +37,8 @@ public class EhCacheStatisticsProvider implements CacheStatisticsProvider 1 ? 1 : hitRatio); + statistics.setMissRatio(hitRatio > 1 ? 0 : 1 - hitRatio); } return statistics; } From 8c7b8afedb994c5d330c067c03d43f4945adcdd0 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 16 Jun 2015 10:31:24 +0200 Subject: [PATCH 2/2] Polish --- .../boot/actuate/cache/EhCacheStatisticsProvider.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java index 98301e36295..6d4ea92afb5 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/EhCacheStatisticsProvider.java @@ -37,8 +37,10 @@ public class EhCacheStatisticsProvider implements CacheStatisticsProvider 1 ? 1 : hitRatio); - statistics.setMissRatio(hitRatio > 1 ? 0 : 1 - hitRatio); + // ratio is calculated 'racily' and can drift marginally above unity, so we cap it here + double sanitizedHitRatio = hitRatio > 1 ? 1 : hitRatio; + statistics.setHitRatio(sanitizedHitRatio); + statistics.setMissRatio(1 - sanitizedHitRatio); } return statistics; }