use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.
the class PagesWriteThrottleSmokeTest method testThrottle.
/**
* @throws Exception if failed.
*/
@Test
public void testThrottle() throws Exception {
startGrids(2).active(true);
try {
IgniteEx ig = ignite(0);
final int keyCnt = 2_000_000;
final AtomicBoolean run = new AtomicBoolean(true);
final AtomicBoolean zeroDropdown = new AtomicBoolean(false);
final HitRateMetric putRate10secs = new HitRateMetric("putRate10secs", "", 10_000, 20);
final HitRateMetric putRate1sec = new HitRateMetric("putRate1sec", "", 1_000, 20);
GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
while (run.get()) {
System.out.println("Put rate over last 10 seconds: " + (putRate10secs.value() / 10) + " puts/sec, over last 1 second: " + putRate1sec.value());
if (putRate10secs.value() == 0) {
zeroDropdown.set(true);
run.set(false);
}
Thread.sleep(1000);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
run.set(false);
}
}
}, "rate-checker");
final IgniteCache<Integer, TestValue> cache = ig.getOrCreateCache(CACHE_NAME);
GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
long startTs = System.currentTimeMillis();
for (int i = 0; i < keyCnt * 10 && System.currentTimeMillis() - startTs < 3 * 60 * 1000; i++) {
if (!run.get())
break;
cache.put(ThreadLocalRandom.current().nextInt(keyCnt), new TestValue(ThreadLocalRandom.current().nextInt(), ThreadLocalRandom.current().nextInt()));
putRate10secs.increment();
putRate1sec.increment();
}
run.set(false);
}
}, "loader");
while (run.get()) LockSupport.parkNanos(10_000);
if (zeroDropdown.get()) {
slowCheckpointEnabled.set(false);
IgniteInternalFuture cpFut1 = ((IgniteEx) ignite(0)).context().cache().context().database().wakeupForCheckpoint("test");
IgniteInternalFuture cpFut2 = ((IgniteEx) ignite(1)).context().cache().context().database().wakeupForCheckpoint("test");
cpFut1.get();
cpFut2.get();
fail("Put rate degraded to zero for at least 10 seconds");
}
LongAdderMetric totalThrottlingTime = totalThrottlingTime(ig);
assertTrue(totalThrottlingTime.value() > 0);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.
the class MetricsSelfTest method testHitRateMetric.
/**
*/
@Test
public void testHitRateMetric() throws Exception {
long rateTimeInterval = 500;
HitRateMetric metric = mreg.hitRateMetric("testHitRate", null, rateTimeInterval, 10);
assertEquals(0, metric.value());
long startTs = U.currentTimeMillis();
GridTestUtils.runMultiThreaded(metric::increment, 10, "test-thread");
assertTrue(metric.value() > 0 || U.currentTimeMillis() - startTs > rateTimeInterval);
U.sleep(rateTimeInterval * 2);
assertEquals(0, metric.value());
assertEquals(rateTimeInterval, metric.rateTimeInterval());
metric.reset(rateTimeInterval * 2, 10);
assertEquals(rateTimeInterval * 2, metric.rateTimeInterval());
}
use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.
the class MetricsConfigurationTest method testHitRateConfiguration.
/**
* Tests configuration of {@link HitRateMetric}.
*/
@Test
public void testHitRateConfiguration() throws Exception {
try (IgniteEx g = startGrid(0)) {
MetricsMxBean bean = metricsBean(g);
// Empty name.
assertThrowsWithCause(() -> bean.configureHitRateMetric(null, 1), NullPointerException.class);
// Wrong rateTimeInterval value.
assertThrowsWithCause(() -> bean.configureHitRateMetric("io.dataregion.default.AllocationRate", 0), IllegalArgumentException.class);
assertThrowsWithCause(() -> bean.configureHitRateMetric("io.dataregion.default.AllocationRate", -1), IllegalArgumentException.class);
bean.configureHitRateMetric("io.dataregion.default.AllocationRate", 5000);
HitRateMetric allocationRate = g.context().metric().registry(metricName("io.dataregion.default")).findMetric("AllocationRate");
assertEquals(5000, allocationRate.rateTimeInterval());
}
}
Aggregations