Search in sources :

Example 1 with HitRateMetric

use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.

the class MetricsConfigurationTest method testConfigRemovedOnRegistryRemove.

/**
 * Tests metric configuration removed on registry remove.
 */
@Test
public void testConfigRemovedOnRegistryRemove() throws Exception {
    checkOnStartAndRestart((g0, g1) -> {
        MetricRegistry mreg = g0.context().metric().registry(TEST_REG);
        mreg.hitRateMetric(HITRATE_NAME, "test", 10000, 5);
        mreg.histogram(HISTOGRAM_NAME, new long[] { 250, 500 }, "test");
        metricsBean(g0).configureHistogramMetric(metricName(TEST_REG, HISTOGRAM_NAME), BOUNDS);
        metricsBean(g0).configureHitRateMetric(metricName(TEST_REG, HITRATE_NAME), 1000);
    }, (g0, g1) -> {
        MetricRegistry mreg = g0.context().metric().registry(TEST_REG);
        HitRateMetric hitRate = mreg.hitRateMetric(HITRATE_NAME, "test", 10000, 5);
        HistogramMetricImpl histogram = mreg.histogram(HISTOGRAM_NAME, new long[] { 250, 500 }, "test");
        assertEquals(1000, hitRate.rateTimeInterval());
        assertArrayEquals(BOUNDS, histogram.bounds());
        assertEquals((Long) 1000L, g0.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertArrayEquals(BOUNDS, g0.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
        assertEquals((Long) 1000L, g1.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertArrayEquals(BOUNDS, g1.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
        g0.context().metric().remove(TEST_REG);
        assertNull(g0.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertNull(g0.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
        assertNull(g1.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertNull(g1.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
    });
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with HitRateMetric

use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.

the class GridMetricManager method onHitRateConfigChanged.

/**
 * Change {@link HitRateMetric} instance configuration.
 *
 * @param name Metric name.
 * @param rateTimeInterval New rateTimeInterval.
 * @see HistogramMetricImpl#reset(long[])
 */
private void onHitRateConfigChanged(String name, @Nullable Long rateTimeInterval) {
    if (rateTimeInterval == null)
        return;
    A.ensure(rateTimeInterval > 0, "rateTimeInterval should be positive");
    HitRateMetric m = find(name, HitRateMetric.class);
    if (m == null)
        return;
    m.reset(rateTimeInterval);
}
Also used : HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric)

Example 3 with HitRateMetric

use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.

the class PagesWriteThrottleSandboxTest method testThrottle.

/**
 * @throws Exception if failed.
 */
@Test
public void testThrottle() throws Exception {
    startGrids(1).active(true);
    try {
        final Ignite ig = ignite(0);
        final int keyCnt = 4_000_000;
        final AtomicBoolean run = new AtomicBoolean(true);
        final HitRateMetric getRate = new HitRateMetric("getRate", "", 5000, 5);
        GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                while (run.get()) {
                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
                    int key = rnd.nextInt(keyCnt * 2);
                    ignite(0).cache(CACHE_NAME).get(key);
                    getRate.increment();
                }
                return null;
            }
        }, 2, "read-loader");
        final HitRateMetric putRate = new HitRateMetric("putRate", "", 1000, 5);
        GridTestUtils.runAsync(new Runnable() {

            @Override
            public void run() {
                while (run.get()) {
                    long dirtyPages = 0;
                    for (DataRegionMetrics m : ig.dataRegionMetrics()) if (m.getName().equals("dfltDataRegion"))
                        dirtyPages = m.getDirtyPages();
                    long cpBufPages = 0;
                    long cpWrittenPages;
                    AtomicInteger cntr = ((GridCacheDatabaseSharedManager) ((ignite(0)).context().cache().context().database())).getCheckpointer().currentProgress().writtenPagesCounter();
                    cpWrittenPages = cntr == null ? 0 : cntr.get();
                    try {
                        cpBufPages = ((ignite(0)).context().cache().context().database().dataRegion("dfltDataRegion").pageMemory()).checkpointBufferPagesCount();
                    } catch (IgniteCheckedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("@@@ putsPerSec=," + (putRate.value()) + ", getsPerSec=," + (getRate.value()) + ", dirtyPages=," + dirtyPages + ", cpWrittenPages=," + cpWrittenPages + ", cpBufPages=," + cpBufPages);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ignored) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
        }, "metrics-view");
        try (IgniteDataStreamer<Object, Object> ds = ig.dataStreamer(CACHE_NAME)) {
            ds.allowOverwrite(true);
            for (int i = 0; i < keyCnt * 10; i++) {
                ds.addData(ThreadLocalRandom.current().nextInt(keyCnt), new TestValue(ThreadLocalRandom.current().nextInt(), ThreadLocalRandom.current().nextInt()));
                putRate.increment();
            }
        }
        run.set(false);
    } finally {
        stopAllGrids();
    }
}
Also used : DataRegionMetrics(org.apache.ignite.DataRegionMetrics) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with HitRateMetric

use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.

the class GridMetricManager method remove.

/**
 * Removes metric registry.
 *
 * @param regName Metric registry name.
 * @param removeCfg {@code True} if remove metric configurations.
 */
public void remove(String regName, boolean removeCfg) {
    GridCompoundFuture opsFut = new GridCompoundFuture<>();
    registries.computeIfPresent(regName, (key, mreg) -> {
        notifyListeners(mreg, metricRegRemoveLsnrs, log);
        if (!removeCfg)
            return null;
        DistributedMetaStorage metastorage0 = metastorage;
        if (metastorage0 == null)
            return null;
        try {
            for (Metric m : mreg) {
                if (m instanceof HitRateMetric)
                    opsFut.add(metastorage0.removeAsync(metricName(HITRATE_CFG_PREFIX, m.name())));
                else if (m instanceof HistogramMetric)
                    opsFut.add(metastorage0.removeAsync(metricName(HISTOGRAM_CFG_PREFIX, m.name())));
            }
        } catch (IgniteCheckedException e) {
            throw new IgniteException(e);
        }
        return null;
    });
    try {
        opsFut.markInitialized();
        opsFut.get();
    } catch (NodeStoppingException ignored) {
    // No-op.
    } catch (IgniteCheckedException e) {
        log.error("Failed to remove metrics configuration.", e);
    }
}
Also used : DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteException(org.apache.ignite.IgniteException) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) Metric(org.apache.ignite.spi.metric.Metric) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Example 5 with HitRateMetric

use of org.apache.ignite.internal.processors.metric.impl.HitRateMetric in project ignite by apache.

the class MetricRegistry method hitRateMetric.

/**
 * Creates and register hit rate metric.
 *
 * It will accumulates approximate hit rate statistics.
 * Calculates number of hits in last rateTimeInterval milliseconds.
 *
 * @param rateTimeInterval Rate time interval.
 * @param size Array size for underlying calculations.
 * @return {@link HitRateMetric}
 * @see HitRateMetric
 */
public HitRateMetric hitRateMetric(String name, @Nullable String desc, long rateTimeInterval, int size) {
    String fullName = metricName(regName, name);
    HitRateMetric metric = addMetric(name, new HitRateMetric(fullName, desc, rateTimeInterval, size));
    Long cfgRateTimeInterval = hitRateCfgProvider.apply(fullName);
    if (cfgRateTimeInterval != null)
        metric.reset(cfgRateTimeInterval, DFLT_SIZE);
    return metric;
}
Also used : HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric)

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