Search in sources :

Example 6 with HitRateMetric

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with HitRateMetric

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());
}
Also used : HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with HitRateMetric

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());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) MetricsMxBean(org.apache.ignite.mxbean.MetricsMxBean) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

HitRateMetric (org.apache.ignite.internal.processors.metric.impl.HitRateMetric)8 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DataRegionMetrics (org.apache.ignite.DataRegionMetrics)1 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 DistributedMetaStorage (org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage)1 ReadableDistributedMetaStorage (org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage)1 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)1 AtomicLongMetric (org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric)1 HistogramMetricImpl (org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl)1 LongAdderMetric (org.apache.ignite.internal.processors.metric.impl.LongAdderMetric)1 GridCompoundFuture (org.apache.ignite.internal.util.future.GridCompoundFuture)1