Search in sources :

Example 1 with TcpDiscoveryMetricsUpdateMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryMetricsUpdateMessage in project ignite by apache.

the class CacheMetricsCacheSizeTest method testCacheSize.

/**
 */
@Test
public void testCacheSize() throws Exception {
    startClientGrid(GRID_CNT);
    IgniteCache cacheNode0 = grid(0).cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < ENTITIES_CNT; i++) cacheNode0.put("key-" + i, i);
    GridCacheContext cacheContext = ((GatewayProtectedCacheProxy) cacheNode0).context();
    CacheMetrics cacheMetric = new CacheMetricsSnapshotV2(new CacheMetricsImpl(cacheContext));
    long size = cacheMetric.getCacheSize();
    HashMap<Integer, CacheMetrics> cacheMetrics = new HashMap<>();
    cacheMetrics.put(1, cacheMetric);
    TcpDiscoveryMetricsUpdateMessage msg = new TcpDiscoveryMetricsUpdateMessage(UUID.randomUUID());
    msg.setCacheMetrics(UUID.randomUUID(), cacheMetrics);
    Marshaller marshaller = grid(0).context().config().getMarshaller();
    byte[] buffer = marshaller.marshal(msg);
    Object readObject = marshaller.unmarshal(buffer, getClass().getClassLoader());
    assertTrue(readObject instanceof TcpDiscoveryMetricsUpdateMessage);
    TcpDiscoveryMetricsUpdateMessage msg2 = (TcpDiscoveryMetricsUpdateMessage) readObject;
    Map<Integer, CacheMetrics> cacheMetrics2 = msg2.cacheMetrics().values().iterator().next();
    CacheMetrics cacheMetric2 = cacheMetrics2.values().iterator().next();
    assertEquals("TcpDiscoveryMetricsUpdateMessage serialization error, cacheSize is different", size, cacheMetric2.getCacheSize());
    IgniteCache cacheNode1 = grid(1).cache(DEFAULT_CACHE_NAME);
    IgniteCache cacheNode2 = grid(2).cache(DEFAULT_CACHE_NAME);
    IgniteCache cacheNode3 = grid(3).cache(DEFAULT_CACHE_NAME);
    awaitMetricsUpdate(1);
    assertEquals(ENTITIES_CNT, cacheNode0.metrics().getCacheSize());
    long sizeNode0 = cacheNode0.localMetrics().getCacheSize();
    assertEquals(ENTITIES_CNT, cacheNode1.metrics().getCacheSize());
    long sizeNode1 = cacheNode1.localMetrics().getCacheSize();
    assertEquals(ENTITIES_CNT, cacheNode2.metrics().getCacheSize());
    long sizeNode2 = cacheNode2.localMetrics().getCacheSize();
    assertEquals(ENTITIES_CNT, sizeNode0 + sizeNode1 + sizeNode2);
    // Client metrics
    assertEquals(ENTITIES_CNT, cacheNode3.metrics().getCacheSize());
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Marshaller(org.apache.ignite.marshaller.Marshaller) HashMap(java.util.HashMap) IgniteCache(org.apache.ignite.IgniteCache) TcpDiscoveryMetricsUpdateMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryMetricsUpdateMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with TcpDiscoveryMetricsUpdateMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryMetricsUpdateMessage 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)

Aggregations

CacheMetrics (org.apache.ignite.cache.CacheMetrics)2 TcpDiscoveryMetricsUpdateMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryMetricsUpdateMessage)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)1 ClusterMetrics (org.apache.ignite.cluster.ClusterMetrics)1 Marshaller (org.apache.ignite.marshaller.Marshaller)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1