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());
}
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);
}
}
Aggregations