Search in sources :

Example 16 with CacheMetrics

use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.

the class GridCacheTransactionalAbstractMetricsSelfTest method testRollbacks.

/**
 * @param concurrency Concurrency control.
 * @param isolation Isolation level.
 * @param put Put some data if {@code true}.
 * @throws Exception If failed.
 */
private void testRollbacks(TransactionConcurrency concurrency, TransactionIsolation isolation, boolean put) throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < TX_CNT; i++) {
        Transaction tx = grid(0).transactions().txStart(concurrency, isolation);
        if (put)
            for (int j = 0; j < keyCount(); j++) cache.put(j, j);
        // Waiting 30 ms for metrics. U.currentTimeMillis() method has 10 ms discretization.
        U.sleep(30);
        tx.rollback();
    }
    for (int i = 0; i < gridCount(); i++) {
        TransactionMetrics metrics = grid(i).transactions().metrics();
        CacheMetrics cacheMetrics = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
        assertEquals(0, metrics.txCommits());
        assertEquals(0, cacheMetrics.getCacheTxCommits());
        if (i == 0) {
            assertEquals(TX_CNT, metrics.txRollbacks());
            if (put) {
                assertEquals(TX_CNT, cacheMetrics.getCacheTxRollbacks());
                // Expected metric value should be in microseconds.
                assert cacheMetrics.getAverageTxRollbackTime() > 1000 : cacheMetrics.getAverageTxRollbackTime();
            }
        } else {
            assertEquals(0, metrics.txRollbacks());
            assertEquals(0, cacheMetrics.getCacheTxRollbacks());
        }
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Transaction(org.apache.ignite.transactions.Transaction) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics)

Example 17 with CacheMetrics

use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.

the class IndexMetricsTest method testIndexRebuildingMetric.

/**
 * @throws Exception If failed.
 */
@Test
public void testIndexRebuildingMetric() throws Exception {
    IgniteEx n = startGrid(0);
    n.cluster().active(true);
    String cacheName1 = "cache1";
    String cacheName2 = "cache2";
    IgniteCache<KeyClass, ValueClass> cache1 = n.getOrCreateCache(cacheConfiguration(cacheName1));
    IgniteCache<KeyClass, ValueClass> cache2 = n.getOrCreateCache(cacheConfiguration(cacheName2));
    int entryCnt1 = 100;
    int entryCnt2 = 200;
    for (int i = 0; i < entryCnt1; i++) cache1.put(new KeyClass(i), new ValueClass((long) i));
    for (int i = 0; i < entryCnt2; i++) cache2.put(new KeyClass(i), new ValueClass((long) i));
    List<Path> idxPaths = getIndexBinPaths(cacheName1);
    idxPaths.addAll(getIndexBinPaths(cacheName2));
    stopAllGrids();
    idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    n = startGrid(0);
    BooleanMetric idxRebuildInProgress1 = indexRebuildMetric(n, cacheName1, "IsIndexRebuildInProgress");
    BooleanMetric idxRebuildInProgress2 = indexRebuildMetric(n, cacheName2, "IsIndexRebuildInProgress");
    LongAdderMetric idxRebuildKeyProcessed1 = indexRebuildMetric(n, cacheName1, "IndexRebuildKeyProcessed");
    LongAdderMetric idxRebuildKeyProcessed2 = indexRebuildMetric(n, cacheName2, "IndexRebuildKeyProcessed");
    CacheMetrics cacheMetrics1 = cacheMetrics(n, cacheName1);
    CacheMetrics cacheMetrics2 = cacheMetrics(n, cacheName2);
    CacheMetricsMXBean cacheMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheLocalMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheLocalMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheClusterMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheClusterMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheClusterMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheClusterMetricsMXBeanImpl.class);
    n.cluster().active(true);
    BooleanSupplier[] idxRebuildProgressCache1 = { idxRebuildInProgress1::value, cacheMetrics1::isIndexRebuildInProgress, cacheMetricsMXBean1::isIndexRebuildInProgress };
    BooleanSupplier[] idxRebuildProgressCache2 = { idxRebuildInProgress2::value, cacheMetrics2::isIndexRebuildInProgress, cacheMetricsMXBean2::isIndexRebuildInProgress };
    // It must always be false, because metric is only per node.
    BooleanSupplier[] idxRebuildProgressCluster = { cacheClusterMetricsMXBean1::isIndexRebuildInProgress, cacheClusterMetricsMXBean2::isIndexRebuildInProgress };
    LongSupplier[] idxRebuildKeyProcessedCache1 = { idxRebuildKeyProcessed1::value, cacheMetrics1::getIndexRebuildKeysProcessed, cacheMetricsMXBean1::getIndexRebuildKeysProcessed };
    LongSupplier[] idxRebuildKeyProcessedCache2 = { idxRebuildKeyProcessed2::value, cacheMetrics2::getIndexRebuildKeysProcessed, cacheMetricsMXBean2::getIndexRebuildKeysProcessed };
    // It must always be 0, because metric is only per node.
    LongSupplier[] idxRebuildKeyProcessedCluster = { cacheClusterMetricsMXBean1::getIndexRebuildKeysProcessed, cacheClusterMetricsMXBean2::getIndexRebuildKeysProcessed };
    assertEquals(true, idxRebuildProgressCache1);
    assertEquals(true, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(0, idxRebuildKeyProcessedCache1);
    assertEquals(0, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
    ((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName1);
    n.cache(cacheName1).indexReadyFuture().get(30_000);
    assertEquals(false, idxRebuildProgressCache1);
    assertEquals(true, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
    assertEquals(0, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
    ((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName2);
    n.cache(cacheName2).indexReadyFuture().get(30_000);
    assertEquals(false, idxRebuildProgressCache1);
    assertEquals(false, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
    assertEquals(entryCnt2, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) KeyClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass) BooleanSupplier(java.util.function.BooleanSupplier) Path(java.nio.file.Path) CacheMetrics(org.apache.ignite.cache.CacheMetrics) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) ValueClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass) IgniteEx(org.apache.ignite.internal.IgniteEx) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) LongSupplier(java.util.function.LongSupplier) Test(org.junit.Test)

Example 18 with CacheMetrics

use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.

the class GridCachePartitionedNearDisabledMetricsSelfTest method testGettingRemovedKey.

/**
 * @throws Exception If failed.
 */
@Test
public void testGettingRemovedKey() throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    cache.put(0, 0);
    for (int i = 0; i < gridCount(); i++) {
        Ignite g = grid(i);
        // TODO: getting of removed key will produce 3 inner read operations.
        g.cache(DEFAULT_CACHE_NAME).removeAll();
        assert g.cache(DEFAULT_CACHE_NAME).localSize() == 0;
        g.cache(DEFAULT_CACHE_NAME).mxBean().clear();
    }
    assertNull("Value is not null for key: " + 0, cache.get(0));
    // Check metrics for the whole cache.
    long removes = 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();
        removes += m.getCacheRemovals();
        reads += m.getCacheGets();
        hits += m.getCacheHits();
        misses += m.getCacheMisses();
    }
    assertEquals(0, removes);
    assertEquals(1, reads);
    assertEquals(0, hits);
    assertEquals(1, misses);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Ignite(org.apache.ignite.Ignite) GridCacheTransactionalAbstractMetricsSelfTest(org.apache.ignite.internal.processors.cache.GridCacheTransactionalAbstractMetricsSelfTest) Test(org.junit.Test)

Example 19 with CacheMetrics

use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.

the class GridCachePartitionedNearDisabledMetricsSelfTest method testMisses.

/**
 * {@inheritDoc}
 */
@Test
@Override
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));
        expReads++;
    }
    // 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) GridCacheTransactionalAbstractMetricsSelfTest(org.apache.ignite.internal.processors.cache.GridCacheTransactionalAbstractMetricsSelfTest) Test(org.junit.Test)

Example 20 with CacheMetrics

use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.

the class GridDiscoveryManager method createMetricsProvider.

/**
     * @return Metrics provider.
     */
private DiscoveryMetricsProvider createMetricsProvider() {
    return new DiscoveryMetricsProvider() {

        /** */
        private final long startTime = U.currentTimeMillis();

        /** {@inheritDoc} */
        @Override
        public ClusterMetrics metrics() {
            GridJobMetrics jm = ctx.jobMetric().getJobMetrics();
            ClusterMetricsSnapshot nm = new ClusterMetricsSnapshot();
            nm.setLastUpdateTime(U.currentTimeMillis());
            // Job metrics.
            nm.setMaximumActiveJobs(jm.getMaximumActiveJobs());
            nm.setCurrentActiveJobs(jm.getCurrentActiveJobs());
            nm.setAverageActiveJobs(jm.getAverageActiveJobs());
            nm.setMaximumWaitingJobs(jm.getMaximumWaitingJobs());
            nm.setCurrentWaitingJobs(jm.getCurrentWaitingJobs());
            nm.setAverageWaitingJobs(jm.getAverageWaitingJobs());
            nm.setMaximumRejectedJobs(jm.getMaximumRejectedJobs());
            nm.setCurrentRejectedJobs(jm.getCurrentRejectedJobs());
            nm.setAverageRejectedJobs(jm.getAverageRejectedJobs());
            nm.setMaximumCancelledJobs(jm.getMaximumCancelledJobs());
            nm.setCurrentCancelledJobs(jm.getCurrentCancelledJobs());
            nm.setAverageCancelledJobs(jm.getAverageCancelledJobs());
            nm.setTotalRejectedJobs(jm.getTotalRejectedJobs());
            nm.setTotalCancelledJobs(jm.getTotalCancelledJobs());
            nm.setTotalExecutedJobs(jm.getTotalExecutedJobs());
            nm.setMaximumJobWaitTime(jm.getMaximumJobWaitTime());
            nm.setCurrentJobWaitTime(jm.getCurrentJobWaitTime());
            nm.setAverageJobWaitTime(jm.getAverageJobWaitTime());
            nm.setMaximumJobExecuteTime(jm.getMaximumJobExecuteTime());
            nm.setCurrentJobExecuteTime(jm.getCurrentJobExecuteTime());
            nm.setAverageJobExecuteTime(jm.getAverageJobExecuteTime());
            nm.setCurrentIdleTime(jm.getCurrentIdleTime());
            nm.setTotalIdleTime(jm.getTotalIdleTime());
            nm.setAverageCpuLoad(jm.getAverageCpuLoad());
            // Job metrics.
            nm.setTotalExecutedTasks(ctx.task().getTotalExecutedTasks());
            // VM metrics.
            nm.setAvailableProcessors(metrics.getAvailableProcessors());
            nm.setCurrentCpuLoad(metrics.getCurrentCpuLoad());
            nm.setCurrentGcCpuLoad(metrics.getCurrentGcCpuLoad());
            nm.setHeapMemoryInitialized(metrics.getHeapMemoryInitialized());
            nm.setHeapMemoryUsed(metrics.getHeapMemoryUsed());
            nm.setHeapMemoryCommitted(metrics.getHeapMemoryCommitted());
            nm.setHeapMemoryMaximum(metrics.getHeapMemoryMaximum());
            nm.setHeapMemoryTotal(metrics.getHeapMemoryMaximum());
            nm.setNonHeapMemoryInitialized(metrics.getNonHeapMemoryInitialized());
            nonHeapMemoryUsed(nm);
            nm.setNonHeapMemoryCommitted(metrics.getNonHeapMemoryCommitted());
            nm.setNonHeapMemoryMaximum(metrics.getNonHeapMemoryMaximum());
            nm.setNonHeapMemoryTotal(metrics.getNonHeapMemoryMaximum());
            nm.setUpTime(metrics.getUptime());
            nm.setStartTime(metrics.getStartTime());
            nm.setNodeStartTime(startTime);
            nm.setCurrentThreadCount(metrics.getThreadCount());
            nm.setMaximumThreadCount(metrics.getPeakThreadCount());
            nm.setTotalStartedThreadCount(metrics.getTotalStartedThreadCount());
            nm.setCurrentDaemonThreadCount(metrics.getDaemonThreadCount());
            nm.setTotalNodes(1);
            // Data metrics.
            nm.setLastDataVersion(ctx.cache().lastDataVersion());
            GridIoManager io = ctx.io();
            // IO metrics.
            nm.setSentMessagesCount(io.getSentMessagesCount());
            nm.setSentBytesCount(io.getSentBytesCount());
            nm.setReceivedMessagesCount(io.getReceivedMessagesCount());
            nm.setReceivedBytesCount(io.getReceivedBytesCount());
            nm.setOutboundMessagesQueueSize(io.getOutboundMessagesQueueSize());
            return nm;
        }

        /**
             * @param nm Initializing metrics snapshot.
             */
        private void nonHeapMemoryUsed(ClusterMetricsSnapshot nm) {
            long nonHeapUsed = metrics.getNonHeapMemoryUsed();
            Map<Integer, CacheMetrics> nodeCacheMetrics = cacheMetrics();
            if (nodeCacheMetrics != null) {
                for (Map.Entry<Integer, CacheMetrics> entry : nodeCacheMetrics.entrySet()) {
                    CacheMetrics e = entry.getValue();
                    if (e != null)
                        nonHeapUsed += e.getOffHeapAllocatedSize();
                }
            }
            nm.setNonHeapMemoryUsed(nonHeapUsed);
        }

        /** {@inheritDoc} */
        @Override
        public Map<Integer, CacheMetrics> cacheMetrics() {
            Collection<GridCacheAdapter<?, ?>> caches = ctx.cache().internalCaches();
            if (F.isEmpty(caches))
                return Collections.emptyMap();
            Map<Integer, CacheMetrics> metrics = null;
            for (GridCacheAdapter<?, ?> cache : caches) {
                if (cache.configuration().isStatisticsEnabled() && cache.context().started() && cache.context().affinity().affinityTopologyVersion().topologyVersion() > 0) {
                    if (metrics == null)
                        metrics = U.newHashMap(caches.size());
                    metrics.put(cache.context().cacheId(), cache.localMetrics());
                }
            }
            return metrics == null ? Collections.<Integer, CacheMetrics>emptyMap() : metrics;
        }
    };
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) GridJobMetrics(org.apache.ignite.internal.processors.jobmetrics.GridJobMetrics) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) DiscoveryMetricsProvider(org.apache.ignite.spi.discovery.DiscoveryMetricsProvider) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap)

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