Search in sources :

Example 21 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class CacheGroupsMetricsRebalanceTest method testCacheGroupRebalance.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheGroupRebalance() throws Exception {
    IgniteEx ignite0 = startGrid(0);
    List<String> cacheNames = Arrays.asList(CACHE4, CACHE5);
    int allKeysCount = 0;
    for (String cacheName : cacheNames) {
        Map<Integer, Long> data = new Random().ints(KEYS_COUNT).distinct().boxed().collect(Collectors.toMap(i -> i, i -> (long) i));
        ignite0.getOrCreateCache(cacheName).putAll(data);
        allKeysCount += data.size();
    }
    TestRecordingCommunicationSpi.spi(ignite0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg instanceof GridDhtPartitionSupplyMessage) && CU.cacheId(GROUP2) == ((GridCacheGroupIdMessage) msg).groupId();
        }
    });
    IgniteEx ignite1 = startGrid(1);
    TestRecordingCommunicationSpi.spi(ignite0).waitForBlocked();
    MetricRegistry mreg = ignite1.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, GROUP2));
    LongMetric startTime = mreg.findMetric("RebalancingStartTime");
    LongMetric lastCancelledTime = mreg.findMetric("RebalancingLastCancelledTime");
    LongMetric endTime = mreg.findMetric("RebalancingEndTime");
    LongMetric partitionsLeft = mreg.findMetric("RebalancingPartitionsLeft");
    IntMetric partitionsTotal = mreg.findMetric("RebalancingPartitionsTotal");
    LongMetric receivedKeys = mreg.findMetric("RebalancingReceivedKeys");
    LongMetric receivedBytes = mreg.findMetric("RebalancingReceivedBytes");
    ObjectGauge<Map<UUID, Long>> fullReceivedKeys = mreg.findMetric("RebalancingFullReceivedKeys");
    ObjectGauge<Map<UUID, Long>> histReceivedKeys = mreg.findMetric("RebalancingHistReceivedKeys");
    ObjectGauge<Map<UUID, Long>> fullReceivedBytes = mreg.findMetric("RebalancingFullReceivedBytes");
    ObjectGauge<Map<UUID, Long>> histReceivedBytes = mreg.findMetric("RebalancingHistReceivedBytes");
    assertEquals("During the start of the rebalancing, the number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsLeft.value());
    assertEquals("The total number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsTotal.value());
    long rebalancingStartTime = startTime.value();
    assertNotSame("During rebalancing start, the start time metric must be determined.", -1, startTime.value());
    assertEquals("Rebalancing last cancelled time must be undefined.", -1, lastCancelledTime.value());
    assertEquals("Before the rebalancing is completed, the end time metric must be undefined.", -1, endTime.value());
    ToLongFunction<Map<UUID, Long>> sumFunc = map -> map.values().stream().mapToLong(Long::longValue).sum();
    String zeroReceivedKeysMsg = "Until a partition supply message has been delivered, keys cannot be received.";
    assertEquals(zeroReceivedKeysMsg, 0, receivedKeys.value());
    assertEquals(zeroReceivedKeysMsg, 0, sumFunc.applyAsLong(fullReceivedKeys.value()));
    assertEquals(zeroReceivedKeysMsg, 0, sumFunc.applyAsLong(histReceivedKeys.value()));
    String zeroReceivedBytesMsg = "Until a partition supply message has been delivered, bytes cannot be received.";
    assertEquals(zeroReceivedBytesMsg, 0, receivedBytes.value());
    assertEquals(zeroReceivedBytesMsg, 0, sumFunc.applyAsLong(fullReceivedBytes.value()));
    assertEquals(zeroReceivedBytesMsg, 0, sumFunc.applyAsLong(histReceivedBytes.value()));
    checkSuppliers(Arrays.asList(ignite0.localNode().id()), fullReceivedKeys, histReceivedKeys, fullReceivedBytes, histReceivedBytes);
    TestRecordingCommunicationSpi.spi(ignite0).stopBlock();
    for (String cacheName : cacheNames) ignite1.context().cache().internalCache(cacheName).preloader().rebalanceFuture().get();
    assertEquals("After completion of rebalancing, there are no partitions of the cache group that are" + " left to rebalance.", 0, partitionsLeft.value());
    assertEquals("After completion of rebalancing, the total number of partitions in the metric should be" + " equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsTotal.value());
    assertEquals("After the rebalancing is ended, the rebalancing start time must be equal to the start time " + "measured immediately after the rebalancing start.", rebalancingStartTime, startTime.value());
    assertEquals("Rebalancing last cancelled time must be undefined.", -1, lastCancelledTime.value());
    waitForCondition(() -> endTime.value() != -1, 1000);
    assertTrue("Rebalancing end time must be determined and must be longer than the start time " + "[RebalancingStartTime=" + rebalancingStartTime + ", RebalancingEndTime=" + endTime.value() + "].", rebalancingStartTime < endTime.value());
    String wrongReceivedKeyCntMsg = "The number of currently rebalanced keys for the whole cache group should " + "be equal to the number of entries in the caches.";
    assertEquals(wrongReceivedKeyCntMsg, allKeysCount, receivedKeys.value());
    assertEquals(wrongReceivedKeyCntMsg, allKeysCount, sumFunc.applyAsLong(fullReceivedKeys.value()));
    assertEquals(0, sumFunc.applyAsLong(histReceivedKeys.value()));
    int estimateByteCnt = allKeysCount * (Integer.BYTES + Long.BYTES);
    String wrongReceivedByteCntMsg = "The number of currently rebalanced bytes of this cache group was expected " + "more " + estimateByteCnt + " bytes.";
    assertTrue(wrongReceivedByteCntMsg, receivedBytes.value() > estimateByteCnt);
    assertTrue(wrongReceivedByteCntMsg, sumFunc.applyAsLong(fullReceivedBytes.value()) > estimateByteCnt);
    assertEquals(0, sumFunc.applyAsLong(histReceivedBytes.value()));
    checkSuppliers(Arrays.asList(ignite0.localNode().id()), fullReceivedKeys, histReceivedKeys, fullReceivedBytes, histReceivedBytes);
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) Map(java.util.Map) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ToLongFunction(java.util.function.ToLongFunction) VisorNodeDataCollectorTaskResult(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskResult) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) CACHE_GROUP_METRICS_PREFIX(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) Event(org.apache.ignite.events.Event) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) ObjectGauge(org.apache.ignite.internal.processors.metric.impl.ObjectGauge) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) Message(org.apache.ignite.plugin.extensions.communication.Message) IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL(org.apache.ignite.IgniteSystemProperties.IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) U(org.apache.ignite.internal.util.typedef.internal.U) ClusterNode(org.apache.ignite.cluster.ClusterNode) VisorNodeDataCollectorTask(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTask) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) A(org.apache.ignite.internal.util.typedef.internal.A) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) VisorNodeDataCollectorTaskArg(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskArg) TimeUnit(java.util.concurrent.TimeUnit) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) DFLT_PARTITION_COUNT(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction.DFLT_PARTITION_COUNT) PA(org.apache.ignite.internal.util.typedef.PA) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) CacheMetrics(org.apache.ignite.cache.CacheMetrics) LongMetric(org.apache.ignite.spi.metric.LongMetric) Collections(java.util.Collections) CacheMode(org.apache.ignite.cache.CacheMode) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) IntMetric(org.apache.ignite.spi.metric.IntMetric) Map(java.util.Map) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 22 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class CacheGroupMetricsTest method testAllocatedPages.

/**
 * Test allocated pages counts for cache groups.
 */
@Test
public void testAllocatedPages() throws Exception {
    pds = true;
    cleanPersistenceDir();
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp1 = cacheGroupMetrics(0, "group1");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp2 = cacheGroupMetrics(0, "group2");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp3 = cacheGroupMetrics(0, "cache4");
    GridMetricManager mmgr = ignite.context().metric();
    LongMetric totalPages = mmgr.registry(metricName(DATAREGION_METRICS_PREFIX, "default")).findMetric("TotalAllocatedPages");
    assertEquals(totalPages.value(), mxBean0Grp1.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp2.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp3.get2().<LongMetric>findMetric("TotalAllocatedPages").value());
    for (int cacheIdx = 1; cacheIdx <= 4; cacheIdx++) {
        IgniteCache cache = ignite.cache("cache" + cacheIdx);
        for (int i = 0; i < 10 * cacheIdx; i++) cache.put(i, new byte[100]);
    }
    assertEquals(totalPages.value(), mxBean0Grp1.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp2.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp3.get2().<LongMetric>findMetric("TotalAllocatedPages").value());
}
Also used : CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IgniteCache(org.apache.ignite.IgniteCache) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class GridJobMetricsSelfTest method testGridJobMetrics.

/**
 * Test correct calculation of finished, started, active, canceled metrics of the {@link GridJobProcessor}.
 */
@Test
public void testGridJobMetrics() throws Exception {
    latch = new CountDownLatch(1);
    try (IgniteEx g = startGrid(0)) {
        MetricRegistry mreg = g.context().metric().registry(JOBS_METRICS);
        LongMetric started = mreg.findMetric(STARTED);
        LongMetric active = mreg.findMetric(ACTIVE);
        LongMetric waiting = mreg.findMetric(WAITING);
        LongMetric canceled = mreg.findMetric(CANCELED);
        LongMetric rejected = mreg.findMetric(REJECTED);
        LongMetric finished = mreg.findMetric(FINISHED);
        LongMetric totalExecutionTime = mreg.findMetric(EXECUTION_TIME);
        LongMetric totalWaitingTime = mreg.findMetric(WAITING_TIME);
        assertNotNull(started);
        assertNotNull(active);
        assertNotNull(waiting);
        assertNotNull(canceled);
        assertNotNull(rejected);
        assertNotNull(finished);
        assertNotNull(totalExecutionTime);
        assertNotNull(totalWaitingTime);
        assertEquals(0, started.value());
        assertEquals(0, active.value());
        assertEquals(0, waiting.value());
        assertEquals(0, canceled.value());
        assertEquals(0, rejected.value());
        assertEquals(0, finished.value());
        assertEquals(0, totalExecutionTime.value());
        assertEquals(0, totalWaitingTime.value());
        SimplestTask task = new SimplestTask();
        g.compute().execute(task, 1);
        // Waiting task to finish.
        boolean res = waitForCondition(() -> active.value() == 0, TIMEOUT);
        assertTrue("Active = " + active.value(), res);
        assertEquals(1, started.value());
        assertEquals(0, waiting.value());
        assertEquals(0, canceled.value());
        assertEquals(0, rejected.value());
        assertEquals(1, finished.value());
        // Task should block until latch is down.
        task.block = true;
        ComputeTaskFuture<?> fut = g.compute().executeAsync(task, 1);
        // Waiting task to start execution.
        res = waitForCondition(() -> active.value() == 1, TIMEOUT);
        assertTrue("Active = " + active.value(), res);
        assertEquals(2, started.value());
        assertEquals(0, waiting.value());
        assertEquals(0, canceled.value());
        assertEquals(0, rejected.value());
        assertEquals(1, finished.value());
        // Sleeping to make sure totalExecutionTime will become more the zero.
        Thread.sleep(100);
        // After latch is down, task should finish.
        latch.countDown();
        fut.get(TIMEOUT);
        res = waitForCondition(() -> active.value() == 0, TIMEOUT);
        assertTrue("Active = " + active.value(), res);
        assertTrue("Execution time should be greater then zero.", totalExecutionTime.value() > 0);
        assertEquals(2, finished.value());
        latch = new CountDownLatch(1);
        fut = g.compute().executeAsync(task, 1);
        res = waitForCondition(() -> active.value() == 1, TIMEOUT);
        assertTrue("Active = " + active.value(), res);
        assertEquals(3, started.value());
        assertEquals(0, waiting.value());
        assertEquals(0, canceled.value());
        assertEquals(0, rejected.value());
        assertEquals(2, finished.value());
        // First cancel task, then allow it to finish.
        fut.cancel();
        latch.countDown();
        res = waitForCondition(() -> active.value() == 0, TIMEOUT);
        assertTrue("Active = " + active.value(), res);
        assertEquals(3, started.value());
        assertEquals(0, waiting.value());
        assertEquals(1, canceled.value());
        assertEquals(0, rejected.value());
        res = waitForCondition(() -> finished.value() == 3, TIMEOUT);
        assertTrue("Finished = " + finished.value(), res);
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 24 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class CheckpointTest method testCheckpoint.

/**
 * @throws Exception If failed.
 */
@Test
public void testCheckpoint() throws Exception {
    IgniteEx srv = startGrid();
    srv.cluster().state(ClusterState.ACTIVE);
    MetricRegistry mreg = srv.context().metric().registry(DATASTORAGE_METRIC_PREFIX);
    LongMetric lastStart = mreg.findMetric("LastCheckpointStart");
    // Wait for checkpoint to finish on node start.
    assertTrue(waitForCondition(() -> 0 < lastStart.value(), TIMEOUT));
    lastStart.reset();
    startCollectStatistics();
    forceCheckpoint();
    assertTrue(waitForCondition(() -> 0 < lastStart.value(), TIMEOUT));
    AtomicInteger cnt = new AtomicInteger();
    stopCollectStatisticsAndRead(new TestHandler() {

        @Override
        public void checkpoint(UUID nodeId, long beforeLockDuration, long lockWaitDuration, long listenersExecDuration, long markDuration, long lockHoldDuration, long pagesWriteDuration, long fsyncDuration, long walCpRecordFsyncDuration, long writeCpEntryDuration, long splitAndSortCpPagesDuration, long totalDuration, long cpStartTime, int pagesSize, int dataPagesWritten, int cowPagesWritten) {
            assertEquals(srv.localNode().id(), nodeId);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointBeforeLockDuration").value(), beforeLockDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointLockWaitDuration").value(), lockWaitDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointListenersExecuteDuration").value(), listenersExecDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointMarkDuration").value(), markDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointLockHoldDuration").value(), lockHoldDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointPagesWriteDuration").value(), pagesWriteDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointFsyncDuration").value(), fsyncDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointWalRecordFsyncDuration").value(), walCpRecordFsyncDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointWriteEntryDuration").value(), writeCpEntryDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointSplitAndSortPagesDuration").value(), splitAndSortCpPagesDuration);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointDuration").value(), totalDuration);
            assertEquals(lastStart.value(), cpStartTime);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointTotalPagesNumber").value(), pagesSize);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointDataPagesNumber").value(), dataPagesWritten);
            assertEquals(mreg.<LongMetric>findMetric("LastCheckpointCopiedOnWritePagesNumber").value(), cowPagesWritten);
            cnt.incrementAndGet();
        }
    });
    assertEquals(1, cnt.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) UUID(java.util.UUID) Test(org.junit.Test)

Example 25 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class TcpCommunicationMetricsListener method collectMessagesCountByType.

/**
 * Collect messages count by type
 */
protected Map<String, Long> collectMessagesCountByType(String prefix) {
    Map<String, Long> res = new HashMap<>();
    prefix = metricName(COMMUNICATION_METRICS_GROUP_NAME, prefix);
    for (Metric metric : mreg) {
        if (metric.name().startsWith(prefix)) {
            short directType = Short.parseShort(metric.name().substring(prefix.length()));
            Map<Short, String> msgTypeMap0 = msgTypeMap;
            if (msgTypeMap0 != null) {
                String typeName = msgTypeMap0.get(directType);
                if (typeName != null)
                    res.put(typeName, ((LongMetric) metric).value());
            }
        }
    }
    return res;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) Metric(org.apache.ignite.spi.metric.Metric) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Aggregations

LongMetric (org.apache.ignite.spi.metric.LongMetric)34 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)27 Test (org.junit.Test)24 IgniteEx (org.apache.ignite.internal.IgniteEx)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 Ignite (org.apache.ignite.Ignite)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ArrayList (java.util.ArrayList)5 IntMetric (org.apache.ignite.spi.metric.IntMetric)5 UUID (java.util.UUID)4 Metric (org.apache.ignite.spi.metric.Metric)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Function (java.util.function.Function)3 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3