Skip to content

Commit

Permalink
ISPN-7745 clusterwide-hit-ratio returns NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson authored and Gustavo Fernandes committed May 22, 2017
1 parent 7ded642 commit c76d0b5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
Expand Up @@ -371,22 +371,19 @@ private void updateTimeSinceStart(List<Map<String, Number>> responseList) {


private void updateRatios(List<Map<String, Number>> responseList) { private void updateRatios(List<Map<String, Number>> responseList) {
long totalHits = 0; long totalHits = 0;
long totalRetrievals = 0;
long sumOfAllReads = 0; long sumOfAllReads = 0;
long sumOfAllWrites = 0; long sumOfAllWrites = 0;
double hitRatio = 0;
double rwRatio = 0;
for (Map<String, Number> m : responseList) { for (Map<String, Number> m : responseList) {
totalHits += m.get(HITS).longValue(); long hits = m.get(HITS).longValue();
sumOfAllReads += (totalHits + m.get(MISSES).longValue()); long misses = m.get(MISSES).longValue();
totalHits += hits;
sumOfAllReads += (totalHits + misses);
sumOfAllWrites += m.get(STORES).longValue(); sumOfAllWrites += m.get(STORES).longValue();
totalRetrievals += (hits + misses);
} }
if (sumOfAllWrites > 0) { this.hitRatio = totalRetrievals > 0 ? (double) totalHits / totalRetrievals : 0;
rwRatio = (double) sumOfAllReads / sumOfAllWrites; this.readWriteRatio = sumOfAllWrites > 0 ? (double) sumOfAllReads / sumOfAllWrites : 0;
hitRatio = (double) totalHits / sumOfAllReads;
}

this.hitRatio = hitRatio;
this.readWriteRatio = rwRatio;
} }


private static <T extends AsyncInterceptor> T getFirstInterceptorWhichExtends(AdvancedCache<?, ?> cache, private static <T extends AsyncInterceptor> T getFirstInterceptorWhichExtends(AdvancedCache<?, ?> cache,
Expand Down
37 changes: 22 additions & 15 deletions core/src/test/java/org/infinispan/jmx/AbstractClusterMBeanTest.java
Expand Up @@ -4,6 +4,7 @@
import javax.management.ObjectName; import javax.management.ObjectName;


import org.infinispan.configuration.cache.CacheMode; import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder; import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.CacheContainer; import org.infinispan.manager.CacheContainer;
Expand All @@ -30,28 +31,34 @@ abstract class AbstractClusterMBeanTest extends MultipleCacheManagersTest {
@Override @Override
protected void createCacheManagers() throws Throwable { protected void createCacheManagers() throws Throwable {
ConfigurationBuilder defaultConfig = new ConfigurationBuilder(); ConfigurationBuilder defaultConfig = new ConfigurationBuilder();
GlobalConfigurationBuilder gcb1 = GlobalConfigurationBuilder.defaultClusteredBuilder(); CacheContainer c1 = createManager(defaultConfig);
gcb1.globalJmxStatistics().enable().allowDuplicateDomains(true).jmxDomain(jmxDomain) CacheContainer c2 = createManager(defaultConfig);
.mBeanServerLookup(new PerThreadMBeanServerLookup()); CacheContainer c3 = createManager(defaultConfig);
CacheContainer cacheManager1 = TestCacheManagerFactory.createClusteredCacheManager(gcb1, defaultConfig, registerCacheManager(c1, c2, c3);
new TransportFlags(), true);
cacheManager1.start();

GlobalConfigurationBuilder gcb2 = GlobalConfigurationBuilder.defaultClusteredBuilder();
gcb2.globalJmxStatistics().enable().allowDuplicateDomains(true).jmxDomain(jmxDomain)
.mBeanServerLookup(new PerThreadMBeanServerLookup());
CacheContainer cacheManager2 = TestCacheManagerFactory.createClusteredCacheManager(gcb2, defaultConfig,
new TransportFlags(), true);
cacheManager2.start();

registerCacheManager(cacheManager1, cacheManager2);


ConfigurationBuilder cb = new ConfigurationBuilder(); ConfigurationBuilder cb = new ConfigurationBuilder();
cb.clustering().cacheMode(CacheMode.REPL_SYNC).jmxStatistics().enable(); cb.clustering().cacheMode(CacheMode.REPL_SYNC).jmxStatistics().enable();
defineConfigurationOnAllManagers(cachename, cb); defineConfigurationOnAllManagers(cachename, cb);
waitForClusterToForm(cachename); waitForClusterToForm(cachename);
} }


private CacheContainer createManager(ConfigurationBuilder builder) {
GlobalConfigurationBuilder gcb1 = GlobalConfigurationBuilder.defaultClusteredBuilder();
gcb1.globalJmxStatistics().enable().allowDuplicateDomains(true).jmxDomain(jmxDomain)
.mBeanServerLookup(new PerThreadMBeanServerLookup());
CacheContainer cacheManager = TestCacheManagerFactory.createClusteredCacheManager(gcb1, builder,
new TransportFlags(), true);
cacheManager.start();
return cacheManager;
}

void assertAttributeValue(MBeanServer mBeanServer, ObjectName oName, String attrName, double expectedValue)
throws Exception {
String receivedVal = mBeanServer.getAttribute(oName, attrName).toString();
assert Double.parseDouble(receivedVal) == expectedValue : "expecting " + expectedValue + " for " + attrName
+ ", but received " + receivedVal;
}

void assertAttributeValue(MBeanServer mBeanServer, ObjectName oName, String attrName, long expectedValue) void assertAttributeValue(MBeanServer mBeanServer, ObjectName oName, String attrName, long expectedValue)
throws Exception { throws Exception {
String receivedVal = mBeanServer.getAttribute(oName, attrName).toString(); String receivedVal = mBeanServer.getAttribute(oName, attrName).toString();
Expand Down
Expand Up @@ -42,16 +42,19 @@ public void testClusterStats() throws Exception {
cache1.put("a3", "b3"); cache1.put("a3", "b3");
cache1.put("a4", "b4"); cache1.put("a4", "b4");


assertAttributeValue(mBeanServer, clusterStats, "HitRatio", 0.0);
assertAttributeValue(mBeanServer, clusterStats, "NumberOfEntries", 4); assertAttributeValue(mBeanServer, clusterStats, "NumberOfEntries", 4);
assertAttributeValue(mBeanServer, clusterStats, "Stores", 4); assertAttributeValue(mBeanServer, clusterStats, "Stores", 4);
assertAttributeValue(mBeanServer, clusterStats, "Evictions", 0); assertAttributeValue(mBeanServer, clusterStats, "Evictions", 0);
assertAttributeValueGreaterThanOrEqualTo(mBeanServer, clusterStats, "AverageWriteTime", 0);


cache1.remove("a1"); cache1.remove("a1");
cache1.get("a1");
cache1.get("a2");


//sleep so we pick up refreshed values after remove //sleep so we pick up refreshed values after remove
TestingUtil.sleepThread(AbstractClusterStats.DEFAULT_STALE_STATS_THRESHOLD + 1000); TestingUtil.sleepThread(AbstractClusterStats.DEFAULT_STALE_STATS_THRESHOLD + 1000);


assertAttributeValue(mBeanServer, clusterStats, "HitRatio", 0.5);
assertAttributeValue(mBeanServer, clusterStats, "RemoveHits", 1); assertAttributeValue(mBeanServer, clusterStats, "RemoveHits", 1);
assertAttributeValue(mBeanServer, clusterStats, "RemoveMisses", 0); assertAttributeValue(mBeanServer, clusterStats, "RemoveMisses", 0);


Expand Down

0 comments on commit c76d0b5

Please sign in to comment.