Search in sources :

Example 16 with DataRegionMetrics

use of org.apache.ignite.DataRegionMetrics in project ignite by apache.

the class IgniteDataStorageMetricsSelfTest method testPersistenceMetrics.

/**
 * @throws Exception if failed.
 */
@Test
public void testPersistenceMetrics() throws Exception {
    final IgniteEx ig = startGrid(0);
    ig.active(true);
    try {
        IgniteCache<Object, Object> cache = ig.cache("cache");
        for (int i = 0; i < 10; i++) cache.put(i, new Person("first-" + i, "last-" + i));
        IgniteCache<Object, Object> cacheNp = ig.cache("cache-np");
        for (int i = 0; i < 10; i++) cacheNp.put(i, new Person("first-" + i, "last-" + i));
        DataRegionMetrics memMetrics = ig.dataRegionMetrics("dflt-plc");
        assertNotNull(memMetrics);
        assertTrue(memMetrics.getDirtyPages() > 0);
        assertTrue(memMetrics.getPagesFillFactor() > 0);
        memMetrics = ig.dataRegionMetrics("no-persistence");
        assertNotNull(memMetrics);
        assertTrue(memMetrics.getTotalAllocatedPages() > 0);
        assertTrue(memMetrics.getPagesFillFactor() > 0);
        ig.context().cache().context().database().waitForCheckpoint("test");
        assertTrue(waitForCondition(new PAX() {

            @Override
            public boolean applyx() {
                DataStorageMetrics pMetrics = ig.dataStorageMetrics();
                assertNotNull(pMetrics);
                return pMetrics.getLastCheckpointTotalPagesNumber() != 0 && pMetrics.getLastCheckpointDataPagesNumber() != 0;
            }
        }, 10_000));
    } finally {
        stopAllGrids();
    }
}
Also used : DataStorageMetrics(org.apache.ignite.DataStorageMetrics) PAX(org.apache.ignite.internal.util.typedef.PAX) IgniteEx(org.apache.ignite.internal.IgniteEx) DataRegionMetrics(org.apache.ignite.DataRegionMetrics) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 17 with DataRegionMetrics

use of org.apache.ignite.DataRegionMetrics in project ignite by apache.

the class IgnitePdsDataRegionMetricsTest method testMemoryUsageSingleNode.

/**
 */
@Test
public void testMemoryUsageSingleNode() throws Exception {
    DataRegionMetrics initMetrics = null;
    for (int iter = 0; iter < ITERATIONS; iter++) {
        final IgniteEx node = startGrid(0);
        node.cluster().active(true);
        DataRegionMetrics currMetrics = getDfltRegionMetrics(node);
        if (initMetrics == null)
            initMetrics = currMetrics;
        assertTrue(currMetrics.getTotalAllocatedPages() >= currMetrics.getPhysicalMemoryPages());
        final IgniteCache<String, String> cache = node.cache(DEFAULT_CACHE_NAME);
        Map<String, String> map = new HashMap<>();
        for (int batch = 0; batch < BATCHES; batch++) {
            int nPuts = BATCH_SIZE_LOW + ThreadLocalRandom.current().nextInt(BATCH_SIZE_HIGH - BATCH_SIZE_LOW);
            for (int i = 0; i < nPuts; i++) map.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
            cache.putAll(map);
            forceCheckpoint(node);
            checkMetricsConsistency(node);
        }
        currMetrics = getDfltRegionMetrics(node);
        // Make sure metrics are rising
        assertTrue(currMetrics.getPhysicalMemoryPages() > initMetrics.getPhysicalMemoryPages());
        assertTrue(currMetrics.getTotalAllocatedPages() > initMetrics.getTotalAllocatedPages());
        stopGrid(0, true);
    }
}
Also used : HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) DataRegionMetrics(org.apache.ignite.DataRegionMetrics) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 18 with DataRegionMetrics

use of org.apache.ignite.DataRegionMetrics in project ignite by apache.

the class FillFactorMetricTest method testFillAndEmpty.

/**
 * throws if failed.
 */
@Test
public void testFillAndEmpty() throws Exception {
    final AtomicBoolean stopLoadFlag = new AtomicBoolean();
    final AtomicBoolean doneFlag = new AtomicBoolean();
    startGrids(NODES);
    grid(0).getOrCreateCache(cacheCfg());
    final int pageSize = grid(0).configuration().getDataStorageConfiguration().getPageSize();
    IgniteInternalFuture printStatFut = GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            while (!doneFlag.get()) {
                log.info("Stat nodes:");
                printStat(0);
                printStat(1);
                try {
                    U.sleep(1000);
                } catch (IgniteInterruptedCheckedException e) {
                    return;
                }
            }
        }

        protected void printStat(int node) {
            DataRegionMetrics m = grid(node).dataRegionMetrics(MY_DATA_REGION);
            float fillFactor = m.getPagesFillFactor();
            long usedMem = (long) ((m.getPhysicalMemoryPages() * pageSize) * fillFactor);
            log.info(String.format("Stat node-%d:\t%d\t%f\t%d", node, m.getPhysicalMemoryPages(), fillFactor, usedMem));
            curFillFactor[node] = fillFactor;
        }
    });
    for (int iter = 0; iter < 3; iter++) {
        log.info("Going upward");
        stopLoadFlag.set(false);
        recordsInCache.set(0);
        IgniteInternalFuture loadFut = GridTestUtils.runAsync(new Runnable() {

            @Override
            public void run() {
                IgniteCache<Object, Object> cache = grid(0).cache(MY_CACHE);
                while (!stopLoadFlag.get()) {
                    int i = recordsInCache.incrementAndGet();
                    final long res = (i * i) % LARGE_PRIME;
                    cache.put(res, new byte[1 << (res % 16)]);
                    try {
                        // Steadily add entries to cache but avoid overconsumption of RAM and CPU
                        Thread.sleep(1);
                    } catch (InterruptedException ie) {
                        return;
                    }
                }
            }
        });
        // Wait for cache to be reasonably full
        U.sleep(6_000);
        stopLoadFlag.set(true);
        loadFut.get();
        // Fill factor will typically be 0.98
        for (float fillFactor : curFillFactor) assertTrue("FillFactor too low: " + fillFactor, fillFactor > 0.9);
        log.info("Going downward");
        IgniteInternalFuture clearFut = GridTestUtils.runAsync(new Runnable() {

            @Override
            public void run() {
                IgniteCache<Object, Object> cache = grid(0).cache(MY_CACHE);
                int i;
                while ((i = recordsInCache.getAndDecrement()) > 0) {
                    final long res = (i * i) % LARGE_PRIME;
                    cache.remove(res);
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException ie) {
                        return;
                    }
                }
            }
        });
        // Wait for cache to be cleared
        clearFut.get();
        // fill factor after cache cleaning will about 0.99, no more obsolete typically value 0.8
        for (float fillFactor : curFillFactor) assertTrue("FillFactor too low: " + fillFactor, fillFactor > 0.9);
    }
    doneFlag.set(true);
    printStatFut.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DataRegionMetrics(org.apache.ignite.DataRegionMetrics) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

DataRegionMetrics (org.apache.ignite.DataRegionMetrics)18 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Ignite (org.apache.ignite.Ignite)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 DataStorageMetrics (org.apache.ignite.DataStorageMetrics)1 IgniteCache (org.apache.ignite.IgniteCache)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)1 PageMemoryImpl (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl)1