use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class GridCacheAbstractMetricsSelfTest method testMisses.
/**
* @throws Exception If failed.
*/
@Test
public void testMisses() throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
int keyCnt = keyCount();
int expReads = 0;
// Get a few keys missed keys.
for (int i = 0; i < keyCnt; i++) {
assertNull("Value is not null for key: " + i, cache.get(i));
if (cache.getConfiguration(CacheConfiguration.class).getCacheMode() == CacheMode.REPLICATED || affinity(cache).isPrimary(grid(0).localNode(), i))
expReads++;
else
expReads += 2;
}
// Check metrics for the whole cache.
long puts = 0;
long reads = 0;
long hits = 0;
long misses = 0;
for (int i = 0; i < gridCount(); i++) {
CacheMetrics m = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
puts += m.getCachePuts();
reads += m.getCacheGets();
hits += m.getCacheHits();
misses += m.getCacheMisses();
}
assertEquals(0, puts);
assertEquals(expReads, reads);
assertEquals(0, hits);
assertEquals(expReads, misses);
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class GridCacheAbstractMetricsSelfTest method testPutsReads.
/**
* @throws Exception If failed.
*/
@Test
public void testPutsReads() throws Exception {
IgniteCache<Integer, Integer> cache0 = grid(0).cache(DEFAULT_CACHE_NAME);
int keyCnt = keyCount();
int expReads = 0;
int expMisses = 0;
// Put and get a few keys.
for (int i = 0; i < keyCnt; i++) {
// +1 put
cache0.getAndPut(i, i);
boolean isPrimary = affinity(cache0).isPrimary(grid(0).localNode(), i);
expReads += expectedReadsPerPut(isPrimary);
expMisses += expectedMissesPerPut(isPrimary);
info("Puts: " + cache0.localMetrics().getCachePuts());
for (int j = 0; j < gridCount(); j++) {
IgniteCache<Integer, Integer> cache = grid(j).cache(DEFAULT_CACHE_NAME);
int cacheWrites = (int) cache.localMetrics().getCachePuts();
assertEquals("Wrong cache metrics [i=" + i + ", grid=" + j + ']', i + 1, cacheWrites);
}
// +1 read
assertEquals("Wrong value for key: " + i, Integer.valueOf(i), cache0.get(i));
expReads++;
}
// Check metrics for the whole cache.
int puts = 0;
int reads = 0;
int hits = 0;
int misses = 0;
for (int i = 0; i < gridCount(); i++) {
CacheMetrics m = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
puts += m.getCachePuts();
reads += m.getCacheGets();
hits += m.getCacheHits();
misses += m.getCacheMisses();
}
info("Stats [reads=" + reads + ", hits=" + hits + ", misses=" + misses + ']');
assertEquals(keyCnt * gridCount(), puts);
assertEquals(expReads, reads);
assertEquals(keyCnt, hits);
assertEquals(expMisses, misses);
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class GridCacheAbstractMetricsSelfTest method testMissHitPercentage.
/**
* @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++) {
// +1 read
cache0.getAndPut(i, i);
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);
}
// +1 read
assertEquals("Wrong value for key: " + i, Integer.valueOf(i), cache0.get(i));
}
// 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);
}
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class TcpDiscoveryImpl method processMsgCacheMetrics.
/**
*/
public void processMsgCacheMetrics(TcpDiscoveryMetricsUpdateMessage msg, long tsNanos) {
for (Map.Entry<UUID, TcpDiscoveryMetricsUpdateMessage.MetricsSet> e : msg.metrics().entrySet()) {
UUID nodeId = e.getKey();
TcpDiscoveryMetricsUpdateMessage.MetricsSet metricsSet = e.getValue();
Map<Integer, CacheMetrics> cacheMetrics = msg.hasCacheMetrics(nodeId) ? msg.cacheMetrics().get(nodeId) : Collections.emptyMap();
if (endTimeMetricsSizeProcessWait <= U.currentTimeMillis() && cacheMetrics.size() >= METRICS_QNT_WARN) {
log.warning("The Discovery message has metrics for " + cacheMetrics.size() + " caches.\n" + "To prevent Discovery blocking use -DIGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE=true option.");
endTimeMetricsSizeProcessWait = U.currentTimeMillis() + LOG_WARN_MSG_TIMEOUT;
}
updateMetrics(nodeId, metricsSet.metrics(), cacheMetrics, tsNanos);
for (T2<UUID, ClusterMetrics> t : metricsSet.clientMetrics()) updateMetrics(t.get1(), t.get2(), cacheMetrics, tsNanos);
}
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class GridCacheTransactionalAbstractMetricsSelfTest method doTestSuspendedTxTimeoutRollbacks.
/**
* Metrics test for transaction timeout rollback.
*
* @param concurrency Concurrency control.
* @param isolation Isolation level.
* @throws Exception If failed.
*/
private void doTestSuspendedTxTimeoutRollbacks(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteTransactions transactions = grid(0).transactions();
for (int i = 0; i < TX_CNT; i++) {
Transaction tx = transactions.txStart(concurrency, isolation, TX_TIMEOUT, 0);
cache.put(1, 1);
tx.suspend();
boolean res = GridTestUtils.waitForCondition(() -> tx.state() == ROLLED_BACK, TX_TIMEOUT * 10);
assertTrue(res);
tx.close();
}
TransactionMetrics txMetrics = transactions.metrics();
CacheMetrics cacheMetrics = cache.localMetrics();
assertEquals(0, txMetrics.txCommits());
assertEquals(0, cacheMetrics.getCacheTxCommits());
assertEquals(TX_CNT, txMetrics.txRollbacks());
assertEquals(TX_CNT, cacheMetrics.getCacheTxRollbacks());
assertTrue(cacheMetrics.getAverageTxRollbackTime() > 0);
for (int i = 1; i < gridCount(); i++) {
txMetrics = grid(i).transactions().metrics();
cacheMetrics = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
assertEquals(0, txMetrics.txCommits());
assertEquals(0, cacheMetrics.getCacheTxCommits());
assertEquals(0, txMetrics.txRollbacks());
assertEquals(0, cacheMetrics.getCacheTxRollbacks());
}
}
Aggregations