/** {@inheritDoc} */ @Override public float getCacheHitPercentage() { return cache.clusterMetrics().getCacheHitPercentage(); }
/** * @throws Exception If failed. */ @Test public void testMissHitPercentage() throws Exception { IgniteCache<Integer, Integer> cache0 = grid(0).cache(DEFAULT_CACHE_NAME); final int keyCnt = keyCount(); // Put and get a few keys. for (int i = 0; i < keyCnt; i++) { cache0.getAndPut(i, i); // +1 read info("Puts: " + cache0.localMetrics().getCachePuts()); for (int j = 0; j < gridCount(); j++) { IgniteCache<Integer, Integer> cache = grid(j).cache(DEFAULT_CACHE_NAME); long cacheWrites = cache.localMetrics().getCachePuts(); assertEquals("Wrong cache metrics [i=" + i + ", grid=" + j + ']', i + 1, cacheWrites); } assertEquals("Wrong value for key: " + i, Integer.valueOf(i), cache0.get(i)); // +1 read } // Check metrics for the whole cache. for (int i = 0; i < gridCount(); i++) { CacheMetrics m = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics(); assertEquals(m.getCacheHits() * 100f / m.getCacheGets(), m.getCacheHitPercentage(), 0.1f); assertEquals(m.getCacheMisses() * 100f / m.getCacheGets(), m.getCacheMissPercentage(), 0.1f); } }
/** * @throws Exception If failed. */ @Test public void testEntryProcessorRemove() throws Exception { IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); cache.put(1, 20); int result = cache.invoke(1, new EntryProcessor<Integer, Integer, Integer>() { @Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException { Integer result = entry.getValue(); entry.remove(); return result; } }); assertEquals(1L, cache.localMetrics().getCachePuts()); assertEquals(20, result); assertEquals(1L, cache.localMetrics().getCacheHits()); assertEquals(100.0f, cache.localMetrics().getCacheHitPercentage()); assertEquals(0L, cache.localMetrics().getCacheMisses()); assertEquals(0f, cache.localMetrics().getCacheMissPercentage()); assertEquals(1L, cache.localMetrics().getCachePuts()); assertEquals(1L, cache.localMetrics().getCacheRemovals()); assertEquals(0L, cache.localMetrics().getCacheEvictions()); assert cache.localMetrics().getAveragePutTime() >= 0; assert cache.localMetrics().getAverageGetTime() >= 0; assert cache.localMetrics().getAverageRemoveTime() >= 0; }
/** * @throws Exception If failed. */ @Test public void testEntryProcessorRemove() throws Exception { IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); cache.put(1, 20); int result = cache.invoke(1, new EntryProcessor<Integer, Integer, Integer>() { @Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException { Integer result = entry.getValue(); entry.remove(); return result; } }); assertEquals(1L, cache.localMetrics().getCachePuts()); assertEquals(20, result); assertEquals(1L, cache.localMetrics().getCacheHits()); assertEquals(100.0f, cache.localMetrics().getCacheHitPercentage()); assertEquals(0L, cache.localMetrics().getCacheMisses()); assertEquals(0f, cache.localMetrics().getCacheMissPercentage()); assertEquals(1L, cache.localMetrics().getCachePuts()); assertEquals(1L, cache.localMetrics().getCacheRemovals()); assertEquals(0L, cache.localMetrics().getCacheEvictions()); assert cache.localMetrics().getAveragePutTime() >= 0; assert cache.localMetrics().getAverageGetTime() >= 0; assert cache.localMetrics().getAverageRemoveTime() >= 0; }
/** {@inheritDoc} */ @Override public float getCacheHitPercentage() { return cache.clusterMetrics().getCacheHitPercentage(); }
writer.writeFloat(metrics.getCacheHitPercentage()); writer.writeLong(metrics.getCacheMisses()); writer.writeFloat(metrics.getCacheMissPercentage());
writer.writeFloat(metrics.getCacheHitPercentage()); writer.writeLong(metrics.getCacheMisses()); writer.writeFloat(metrics.getCacheMissPercentage());