Search in sources :

Example 11 with CacheMetrics

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);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 12 with CacheMetrics

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);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Test(org.junit.Test)

Example 13 with CacheMetrics

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);
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Test(org.junit.Test)

Example 14 with CacheMetrics

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);
    }
}
Also used : IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) CacheMetrics(org.apache.ignite.cache.CacheMetrics) TcpDiscoveryMetricsUpdateMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryMetricsUpdateMessage) ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) UUID(java.util.UUID) Map(java.util.Map)

Example 15 with CacheMetrics

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());
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Transaction(org.apache.ignite.transactions.Transaction) IgniteTransactions(org.apache.ignite.IgniteTransactions) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics)

Aggregations

CacheMetrics (org.apache.ignite.cache.CacheMetrics)30 Test (org.junit.Test)15 Ignite (org.apache.ignite.Ignite)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)8 IgniteCache (org.apache.ignite.IgniteCache)5 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 Transaction (org.apache.ignite.transactions.Transaction)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 IgniteClusterNode (org.apache.ignite.internal.managers.discovery.IgniteClusterNode)3 CacheMetricsMXBean (org.apache.ignite.mxbean.CacheMetricsMXBean)3 TransactionMetrics (org.apache.ignite.transactions.TransactionMetrics)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)2 IgniteTransactions (org.apache.ignite.IgniteTransactions)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)2 GridCacheTransactionalAbstractMetricsSelfTest (org.apache.ignite.internal.processors.cache.GridCacheTransactionalAbstractMetricsSelfTest)2