use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class CacheMetricsForClusterGroupSelfTest method testMetricsStatisticsDisabled.
/**
* Test cluster group metrics in case of statistics disabled.
*
* @throws Exception If failed.
*/
@Test
public void testMetricsStatisticsDisabled() throws Exception {
startGrids();
try {
createCaches(false);
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());
}
assertMetrics(cache1, false);
assertMetrics(cache2, false);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class CacheGroupsMetricsRebalanceTest method testRebalanceEstimateFinishTime.
/**
* @throws Exception If failed.
*/
@Test
public void testRebalanceEstimateFinishTime() throws Exception {
System.setProperty(IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL, String.valueOf(10_000));
Ignite ig1 = startGrid(1);
final int KEYS = 300_000;
try (IgniteDataStreamer<Integer, String> st = ig1.dataStreamer(CACHE1)) {
for (int i = 0; i < KEYS; i++) st.addData(i, CACHE1 + "-" + i);
}
final Ignite ig2 = startGrid(2);
boolean rebalancingStartTimeGot = waitForCondition(() -> ig2.cache(CACHE1).localMetrics().getRebalancingStartTime() != -1L, 5_000);
assertTrue("Unable to resolve rebalancing start time.", rebalancingStartTimeGot);
CacheMetrics metrics = ig2.cache(CACHE1).localMetrics();
long startTime = metrics.getRebalancingStartTime();
long currTime = U.currentTimeMillis();
assertTrue("Invalid start time [startTime=" + startTime + ", currTime=" + currTime + ']', startTime > 0L && (currTime - startTime) >= 0L && (currTime - startTime) <= 5000L);
final CountDownLatch latch = new CountDownLatch(1);
runAsync(() -> {
// Waiting 75% keys will be rebalanced.
int partKeys = KEYS / 2;
final long keysLine = (long) partKeys / 4L;
log.info("Wait until keys left will be less than: " + keysLine);
while (true) {
CacheMetrics m = ig2.cache(CACHE1).localMetrics();
long keyLeft = m.getKeysToRebalanceLeft();
if (keyLeft < keysLine) {
latch.countDown();
break;
}
log.info("Keys left: " + m.getKeysToRebalanceLeft());
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
log.warning("Interrupt thread", e);
Thread.currentThread().interrupt();
}
}
});
assertTrue(latch.await(getTestTimeout(), TimeUnit.MILLISECONDS));
boolean estimatedRebalancingFinishTimeGot = waitForCondition(new PA() {
@Override
public boolean apply() {
return ig2.cache(CACHE1).localMetrics().getEstimatedRebalancingFinishTime() != -1L;
}
}, 5_000L);
assertTrue("Unable to resolve estimated rebalancing finish time.", estimatedRebalancingFinishTimeGot);
long finishTime = ig2.cache(CACHE1).localMetrics().getEstimatedRebalancingFinishTime();
assertTrue("Not a positive estimation of rebalancing finish time: " + finishTime, finishTime > 0L);
currTime = U.currentTimeMillis();
long timePassed = currTime - startTime;
long timeLeft = finishTime - currTime;
// TODO: finishRebalanceLatch gets countdown much earlier because of ForceRebalanceExchangeTask triggered by cache with delay
// assertTrue("Got timeout while waiting for rebalancing. Estimated left time: " + timeLeft,
// finishRebalanceLatch.await(timeLeft + 10_000L, TimeUnit.MILLISECONDS));
boolean allKeysRebalanced = waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ig2.cache(CACHE1).localMetrics().getKeysToRebalanceLeft() == 0;
}
}, timeLeft + ACCEPTABLE_TIME_INACCURACY);
assertTrue("Some keys aren't rebalanced.", allKeysRebalanced);
log.info("[timePassed=" + timePassed + ", timeLeft=" + timeLeft + ", Time to rebalance=" + (finishTime - startTime) + ", startTime=" + startTime + ", finishTime=" + finishTime + ']');
System.clearProperty(IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL);
currTime = U.currentTimeMillis();
log.info("Rebalance time: " + (currTime - startTime));
long diff = finishTime - currTime;
assertTrue("Expected less than " + ACCEPTABLE_TIME_INACCURACY + ", but actual: " + diff, Math.abs(diff) < ACCEPTABLE_TIME_INACCURACY);
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class CacheGroupsMetricsRebalanceTest method testRebalance.
/**
* Checks the correctness of {@link CacheMetrics#getRebalancingKeysRate}.
*
* @throws Exception If failed.
*/
@Test
public void testRebalance() throws Exception {
Ignite ignite = startGrid(0);
IgniteCache<Object, Object> cache1 = ignite.cache(CACHE1);
IgniteCache<Object, Object> cache2 = ignite.cache(CACHE2);
for (int i = 0; i < KEYS_COUNT; i++) {
cache1.put(i, CACHE1 + "-" + i);
if (i % 2 == 0)
cache2.put(i, CACHE2 + "-" + i);
}
ignite = startGrid(1);
awaitPartitionMapExchange(true, true, null, true);
CacheMetrics metrics1 = ignite.cache(CACHE1).localMetrics();
CacheMetrics metrics2 = ignite.cache(CACHE2).localMetrics();
long rate1 = metrics1.getRebalancingKeysRate();
long rate2 = metrics2.getRebalancingKeysRate();
assertTrue(rate1 > 0);
assertTrue(rate2 > 0);
assertTrue(rate1 > rate2);
assertEquals(metrics1.getRebalancedKeys(), rate1);
assertEquals(metrics2.getRebalancedKeys(), rate2);
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class PlatformCache method processOutStream.
/**
* {@inheritDoc}
*/
@Override
public void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
switch(type) {
case OP_GET_NAME:
writer.writeObject(cache.getName());
break;
case OP_LOCAL_METRICS:
{
CacheMetrics metrics = cache.localMetrics();
writeCacheMetrics(writer, metrics);
break;
}
case OP_GLOBAL_METRICS:
{
CacheMetrics metrics = cache.metrics();
writeCacheMetrics(writer, metrics);
break;
}
case OP_GET_CONFIG:
CacheConfiguration ccfg = ((IgniteCache<Object, Object>) cache).getConfiguration(CacheConfiguration.class);
PlatformConfigurationUtils.writeCacheConfiguration(writer, ccfg);
break;
case OP_GET_LOST_PARTITIONS:
Collection<Integer> parts = cache.lostPartitions();
writer.writeInt(parts.size());
for (int p : parts) {
writer.writeInt(p);
}
break;
case OP_QUERY_METRICS:
{
QueryMetrics metrics = cache.queryMetrics();
writeQueryMetrics(writer, metrics);
break;
}
default:
super.processOutStream(type, writer);
}
}
use of org.apache.ignite.cache.CacheMetrics in project ignite by apache.
the class VisorNodeDataCollectorJob method caches.
/**
* Collect caches.
*
* @param res Job result.
* @param arg Task argument.
*/
protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollectorTaskArg arg) {
try {
IgniteConfiguration cfg = ignite.configuration();
GridCacheProcessor cacheProc = ignite.context().cache();
Set<String> cacheGrps = arg.getCacheGroups();
boolean all = F.isEmpty(cacheGrps);
int partitions = 0;
double total = 0;
double ready = 0;
List<VisorCache> resCaches = res.getCaches();
boolean rebalanceInProgress = false;
for (CacheGroupContext grp : cacheProc.cacheGroups()) {
boolean first = true;
for (GridCacheContext cache : grp.caches()) {
long start0 = U.currentTimeMillis();
String cacheName = cache.name();
try {
if (isProxyCache(ignite, cacheName) || isRestartingCache(ignite, cacheName))
continue;
GridCacheAdapter ca = cacheProc.internalCache(cacheName);
if (ca == null || !ca.context().started())
continue;
if (first) {
CacheMetrics cm = ca.localMetrics();
partitions += cm.getTotalPartitionsCount();
long keysTotal = cm.getEstimatedRebalancingKeys();
long keysReady = cm.getRebalancedKeys();
if (keysReady >= keysTotal)
keysReady = Math.max(keysTotal - 1, 0);
total += keysTotal;
ready += keysReady;
if (!rebalanceInProgress && cm.getRebalancingPartitionsCount() > 0)
rebalanceInProgress = true;
first = false;
}
boolean addToRes = arg.getSystemCaches() || !(isSystemCache(cacheName));
if (addToRes && (all || cacheGrps.contains(ca.configuration().getGroupName())))
resCaches.add(new VisorCache(ignite, ca, arg.isCollectCacheMetrics()));
} catch (IllegalStateException | IllegalArgumentException e) {
if (debug && ignite.log() != null)
ignite.log().error("Ignored cache: " + cacheName, e);
} finally {
if (debug)
log(ignite.log(), "Collected cache: " + cacheName, getClass(), start0);
}
}
}
if (partitions == 0)
res.setRebalance(NOTHING_TO_REBALANCE);
else if (total == 0 && rebalanceInProgress)
res.setRebalance(MINIMAL_REBALANCE);
else
res.setRebalance(total > 0 && rebalanceInProgress ? Math.max(ready / total, MINIMAL_REBALANCE) : REBALANCE_COMPLETE);
} catch (Exception e) {
res.setRebalance(REBALANCE_NOT_AVAILABLE);
res.setCachesEx(new VisorExceptionWrapper(e));
}
}
Aggregations