Search in sources :

Example 21 with CacheMetrics

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

the class TcpDiscoveryNode method readExternal.

/**
 * {@inheritDoc}
 */
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    id = U.readUuid(in);
    attrs = U.sealMap(U.<String, Object>readMap(in));
    addrs = U.readCollection(in);
    hostNames = U.readCollection(in);
    discPort = in.readInt();
    sockAddrs = U.toSocketAddresses(this, discPort);
    Object consistentIdAttr = attrs.get(ATTR_NODE_CONSISTENT_ID);
    // Cluster metrics
    byte[] mtr = U.readByteArray(in);
    if (mtr != null)
        metrics = ClusterMetricsSnapshot.deserialize(mtr, 0);
    // Cache metrics
    int size = in.readInt();
    Map<Integer, CacheMetrics> cacheMetrics = size > 0 ? U.<Integer, CacheMetrics>newHashMap(size) : Collections.<Integer, CacheMetrics>emptyMap();
    for (int i = 0; i < size; i++) {
        int id = in.readInt();
        CacheMetrics m = (CacheMetrics) in.readObject();
        cacheMetrics.put(id, m);
    }
    order = in.readLong();
    intOrder = in.readLong();
    ver = (IgniteProductVersion) in.readObject();
    clientRouterNodeId = U.readUuid(in);
    if (isClient())
        consistentId = consistentIdAttr != null ? consistentIdAttr : id;
    else
        consistentId = consistentIdAttr != null ? consistentIdAttr : U.consistentId(addrs, discPort);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics)

Example 22 with CacheMetrics

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

the class CacheGroupsMetricsRebalanceTest method testRebalanceProgressUnderLoad.

/**
 * @throws Exception If failed.
 */
@Test
public void testRebalanceProgressUnderLoad() throws Exception {
    Ignite ignite = startGrids(4);
    IgniteCache<Object, Object> cache1 = ignite.cache(CACHE1);
    Random r = new Random();
    GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 100_000; i++) {
                int next = r.nextInt();
                cache1.put(next, CACHE1 + "-" + next);
            }
        }
    });
    IgniteEx ig = startGrid(4);
    GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 100_000; i++) {
                int next = r.nextInt();
                cache1.put(next, CACHE1 + "-" + next);
            }
        }
    });
    CountDownLatch latch = new CountDownLatch(1);
    ig.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            latch.countDown();
            return false;
        }
    }, EventType.EVT_CACHE_REBALANCE_STOPPED);
    latch.await();
    VisorNodeDataCollectorTaskArg taskArg = new VisorNodeDataCollectorTaskArg();
    taskArg.setCacheGroups(Collections.emptySet());
    VisorTaskArgument<VisorNodeDataCollectorTaskArg> arg = new VisorTaskArgument<>(Collections.singletonList(ignite.cluster().localNode().id()), taskArg, false);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            VisorNodeDataCollectorTaskResult res = ignite.compute().execute(VisorNodeDataCollectorTask.class, arg);
            CacheMetrics snapshot = ig.cache(CACHE1).metrics();
            return snapshot.getRebalancedKeys() > snapshot.getEstimatedRebalancingKeys() && Double.compare(res.getRebalance().get(ignite.cluster().localNode().id()), 1.0) == 0 && snapshot.getRebalancingPartitionsCount() == 0;
        }
    }, 5000);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) Random(java.util.Random) VisorNodeDataCollectorTask(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTask) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorNodeDataCollectorTaskResult(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskResult) Event(org.apache.ignite.events.Event) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) Ignite(org.apache.ignite.Ignite) VisorNodeDataCollectorTaskArg(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskArg) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with CacheMetrics

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

the class CacheMetricsForClusterGroupSelfTest method testMetricsStatisticsEnabled.

/**
 * Test cluster group metrics in case of statistics enabled.
 */
@Test
public void testMetricsStatisticsEnabled() throws Exception {
    startGrids();
    try {
        createCaches(true);
        populateCacheData(cache1, ENTRY_CNT_CACHE1);
        populateCacheData(cache2, ENTRY_CNT_CACHE2);
        readCacheData(cache1, ENTRY_CNT_CACHE1);
        readCacheData(cache2, ENTRY_CNT_CACHE2);
        awaitMetricsUpdate(1);
        Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
        for (ClusterNode node : nodes) {
            Map<Integer, CacheMetrics> metrics = ((IgniteClusterNode) node).cacheMetrics();
            assertNotNull(metrics);
            assertFalse(metrics.isEmpty());
        }
        assertMetrics(cache1, true);
        assertMetrics(cache2, true);
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) CacheMetrics(org.apache.ignite.cache.CacheMetrics) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 24 with CacheMetrics

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

the class CacheMetricsForClusterGroupSelfTest method testMetricsDiscoveryUpdatesDisabled.

/**
 * Tests that only local metrics are updating if discovery updates disabled.
 */
@Test
public void testMetricsDiscoveryUpdatesDisabled() throws Exception {
    System.setProperty(IgniteSystemProperties.IGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE, "true");
    try {
        startGrids();
        try {
            createCaches(true);
            populateCacheData(cache1, ENTRY_CNT_CACHE1);
            populateCacheData(cache2, ENTRY_CNT_CACHE2);
            readCacheData(cache1, ENTRY_CNT_CACHE1);
            readCacheData(cache2, ENTRY_CNT_CACHE2);
            awaitMetricsUpdate(1);
            Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
            for (ClusterNode node : nodes) {
                Map<Integer, CacheMetrics> metrics = ((IgniteClusterNode) node).cacheMetrics();
                assertNotNull(metrics);
                assertTrue(metrics.isEmpty());
            }
            assertOnlyLocalMetricsUpdating(CACHE1);
            assertOnlyLocalMetricsUpdating(CACHE2);
        } finally {
            stopAllGrids();
        }
    } finally {
        System.setProperty(IgniteSystemProperties.IGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE, "false");
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) CacheMetrics(org.apache.ignite.cache.CacheMetrics) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 25 with CacheMetrics

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

the class CacheMetricsForClusterGroupSelfTest method assertOnlyLocalMetricsUpdating.

/**
 * Asserts that only local metrics are updating.
 *
 * @param cacheName Cache name.
 */
private void assertOnlyLocalMetricsUpdating(String cacheName) {
    for (int i = 0; i < GRID_CNT; i++) {
        IgniteCache cache = grid(i).cache(cacheName);
        CacheMetrics clusterMetrics = cache.metrics(grid(i).cluster().forCacheNodes(cacheName));
        CacheMetrics locMetrics = cache.localMetrics();
        assertEquals(clusterMetrics.name(), locMetrics.name());
        assertEquals(0L, clusterMetrics.getCacheGets());
        assertEquals(0L, cache.mxBean().getCacheGets());
        assertEquals(locMetrics.getCacheGets(), cache.localMxBean().getCacheGets());
        assertEquals(0L, clusterMetrics.getCachePuts());
        assertEquals(0L, cache.mxBean().getCachePuts());
        assertEquals(locMetrics.getCachePuts(), cache.localMxBean().getCachePuts());
        assertEquals(0L, clusterMetrics.getCacheHits());
        assertEquals(0L, cache.mxBean().getCacheHits());
        assertEquals(locMetrics.getCacheHits(), cache.localMxBean().getCacheHits());
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) IgniteCache(org.apache.ignite.IgniteCache)

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