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