use of org.apache.ignite.DataRegionMetrics in project ignite by apache.
the class FillFactorMetricTest method testFillAndEmpty.
/**
* throws if failed.
*/
public void testFillAndEmpty() throws Exception {
final AtomicBoolean stopLoadFlag = new AtomicBoolean();
final AtomicBoolean doneFlag = new AtomicBoolean();
startGrids(NODES);
grid(0).getOrCreateCache(cacheCfg());
final int pageSize = grid(0).configuration().getDataStorageConfiguration().getPageSize();
IgniteInternalFuture printStatFut = GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
while (!doneFlag.get()) {
log.info("Stat nodes:");
printStat(0);
printStat(1);
try {
U.sleep(1000);
} catch (IgniteInterruptedCheckedException e) {
return;
}
}
}
protected void printStat(int node) {
DataRegionMetrics m = grid(node).dataRegionMetrics(MY_DATA_REGION);
float fillFactor = m.getPagesFillFactor();
long usedMem = (long) ((m.getPhysicalMemoryPages() * pageSize) * fillFactor);
log.info(String.format("Stat node-%d:\t%d\t%f\t%d", node, m.getPhysicalMemoryPages(), fillFactor, usedMem));
curFillFactor[node] = fillFactor;
}
});
for (int iter = 0; iter < 3; iter++) {
log.info("Going upward");
stopLoadFlag.set(false);
recordsInCache.set(0);
IgniteInternalFuture loadFut = GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
IgniteCache<Object, Object> cache = grid(0).cache(MY_CACHE);
while (!stopLoadFlag.get()) {
int i = recordsInCache.incrementAndGet();
final long res = (i * i) % LARGE_PRIME;
cache.put(res, new byte[1 << (res % 16)]);
try {
// Steadily add entries to cache but avoid overconsumption of RAM and CPU
Thread.sleep(1);
} catch (InterruptedException ie) {
return;
}
}
}
});
// Wait for cache to be reasonably full
U.sleep(6_000);
stopLoadFlag.set(true);
loadFut.get();
// Fill factor will typically be 0.98
for (float fillFactor : curFillFactor) assertTrue("FillFactor too low: " + fillFactor, fillFactor > 0.9);
log.info("Going downward");
IgniteInternalFuture clearFut = GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
IgniteCache<Object, Object> cache = grid(0).cache(MY_CACHE);
int i;
while ((i = recordsInCache.getAndDecrement()) > 0) {
final long res = (i * i) % LARGE_PRIME;
cache.remove(res);
try {
Thread.sleep(1);
} catch (InterruptedException ie) {
return;
}
}
}
});
// Wait for cache to be cleared
clearFut.get();
// Fill factor will typically be 0.8, occupied pages mostly partition metadata
for (float fillFactor : curFillFactor) assertTrue("FillFactor too high: " + fillFactor, fillFactor < 0.85);
}
doneFlag.set(true);
printStatFut.get();
}
Aggregations