Search in sources :

Example 1 with HistogramMetricImpl

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

the class MetricsSelfTest method testHistogram.

/**
 */
@Test
public void testHistogram() throws Exception {
    HistogramMetricImpl h = mreg.histogram("hmtest", new long[] { 10, 100, 500 }, "test");
    List<IgniteInternalFuture> futs = new ArrayList<>();
    int cnt = 10;
    futs.add(runAsync(() -> {
        for (int i = 0; i < cnt; i++) h.value(9);
    }));
    futs.add(runAsync(() -> {
        for (int i = 0; i < cnt * 2; i++) h.value(99);
    }));
    futs.add(runAsync(() -> {
        for (int i = 0; i < cnt * 3; i++) h.value(500);
    }));
    futs.add(runAsync(() -> {
        for (int i = 0; i < cnt * 4; i++) h.value(501);
    }));
    for (IgniteInternalFuture fut : futs) fut.get();
    long[] res = h.value();
    assertEquals(cnt, res[0]);
    assertEquals(cnt * 2, res[1]);
    assertEquals(cnt * 3, res[2]);
    assertEquals(cnt * 4, res[3]);
}
Also used : ArrayList(java.util.ArrayList) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with HistogramMetricImpl

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

the class JmxExporterSpiTest method createTestHistogram.

/**
 */
private void createTestHistogram(MetricRegistry mreg) {
    long[] bounds = new long[] { 50, 500 };
    HistogramMetricImpl histogram = mreg.histogram("histogram", bounds, null);
    histogram.value(10);
    histogram.value(51);
    histogram.value(60);
    histogram.value(600);
    histogram.value(600);
    histogram.value(600);
    histogram = mreg.histogram("histogram_with_underscore", bounds, null);
    histogram.value(10);
    histogram.value(51);
    histogram.value(60);
    histogram.value(600);
    histogram.value(600);
    histogram.value(600);
}
Also used : HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl)

Example 3 with HistogramMetricImpl

use of org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl 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 4 with HistogramMetricImpl

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

the class MetricsConfigurationTest method testConfigRemovedOnCacheRemove.

/**
 * Tests metric configuration removed on registry remove.
 */
@Test
public void testConfigRemovedOnCacheRemove() throws Exception {
    String cacheRegName = cacheMetricsRegistryName("test", false);
    checkOnStartAndRestart((g0, g1) -> {
        g0.createCache("test");
        awaitPartitionMapExchange();
        HistogramMetricImpl getTime = g0.context().metric().registry(cacheRegName).findMetric("GetTime");
        assertNotEquals(BOUNDS.length, getTime.bounds().length);
        metricsBean(g0).configureHistogramMetric(metricName(cacheRegName, "GetTime"), BOUNDS);
        assertArrayEquals(BOUNDS, g0.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
        assertArrayEquals(BOUNDS, g1.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
    }, (g0, g1) -> {
        assertArrayEquals(BOUNDS, g0.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
        assertArrayEquals(BOUNDS, g1.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
        g0.destroyCache("test");
        awaitPartitionMapExchange();
        assertNull(g0.context().distributedMetastorage().read(metricName(cacheRegName, "GetTime")));
        assertNull(g1.context().distributedMetastorage().read(metricName(cacheRegName, "GetTime")));
    });
}
Also used : HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with HistogramMetricImpl

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

the class GridServiceProxy method invokeMethod.

/**
 * Invoke the method.
 *
 * @param mtd Method.
 * @param args Arugments.
 * @param callAttrs Service call context attributes.
 * @return Result.
 */
@SuppressWarnings("BusyWait")
public Object invokeMethod(Method mtd, Object[] args, @Nullable Map<String, Object> callAttrs) throws Throwable {
    if (U.isHashCodeMethod(mtd))
        return System.identityHashCode(proxy);
    else if (U.isEqualsMethod(mtd))
        return proxy == args[0];
    else if (U.isToStringMethod(mtd))
        return GridServiceProxy.class.getSimpleName() + " [name=" + name + ", sticky=" + sticky + ']';
    ctx.gateway().readLock();
    try {
        final long startTime = U.currentTimeMillis();
        while (true) {
            ClusterNode node = null;
            try {
                node = nodeForService(name, sticky);
                if (node == null)
                    throw new IgniteException("Failed to find deployed service: " + name);
                // If service is deployed locally, then execute locally.
                if (node.isLocal()) {
                    ServiceContextImpl svcCtx = ctx.service().serviceContext(name);
                    if (svcCtx != null) {
                        Service svc = svcCtx.service();
                        if (svc != null) {
                            HistogramMetricImpl hist = svcCtx.isStatisticsEnabled() ? svcCtx.metrics().findMetric(mtd.getName()) : null;
                            return hist == null ? callServiceLocally(svc, mtd, args, callAttrs) : measureCall(hist, () -> callServiceLocally(svc, mtd, args, callAttrs));
                        }
                    }
                } else {
                    ctx.task().setThreadContext(TC_IO_POLICY, GridIoPolicy.SERVICE_POOL);
                    // Execute service remotely.
                    return unmarshalResult(ctx.closure().callAsyncNoFailover(GridClosureCallMode.BROADCAST, new ServiceProxyCallable(methodName(mtd), name, mtd.getParameterTypes(), args, callAttrs), Collections.singleton(node), false, waitTimeout, true).get());
                }
            } catch (InvocationTargetException e) {
                // For local services rethrow original exception.
                throw e.getTargetException();
            } catch (RuntimeException | Error e) {
                throw e;
            } catch (IgniteCheckedException e) {
                // Check if ignorable exceptions are in the cause chain.
                Throwable ignorableCause = X.cause(e, ClusterTopologyCheckedException.class);
                if (ignorableCause == null)
                    ignorableCause = X.cause(e, GridServiceNotFoundException.class);
                if (ignorableCause != null) {
                    if (log.isDebugEnabled())
                        log.debug("Service was not found or topology changed (will retry): " + ignorableCause.getMessage());
                } else {
                    // Rethrow original service method exception so that calling user code can handle it correctly.
                    ServiceProxyException svcProxyE = X.cause(e, ServiceProxyException.class);
                    if (svcProxyE != null)
                        throw svcProxyE.getCause();
                    throw U.convertException(e);
                }
            } catch (Exception e) {
                throw new IgniteException(e);
            }
            // If we are here, that means that service was not found
            // or topology was changed. In this case, we erase the
            // previous sticky node and try again.
            rmtNode.compareAndSet(node, null);
            // Add sleep between retries to avoid busy-wait loops.
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IgniteException(e);
            }
            if (waitTimeout > 0 && U.currentTimeMillis() - startTime >= waitTimeout)
                throw new IgniteException("Service acquire timeout was reached, stopping. [timeout=" + waitTimeout + "]");
        }
    } finally {
        ctx.gateway().readUnlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) PlatformService(org.apache.ignite.internal.processors.platform.services.PlatformService) Service(org.apache.ignite.services.Service) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) InvocationTargetException(java.lang.reflect.InvocationTargetException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

HistogramMetricImpl (org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl)18 Test (org.junit.Test)13 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)7 IgniteCache (org.apache.ignite.IgniteCache)6 CacheMetrics (org.apache.ignite.cache.CacheMetrics)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 U (org.apache.ignite.internal.util.typedef.internal.U)6 Transaction (org.apache.ignite.transactions.Transaction)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 LongMetric (org.apache.ignite.spi.metric.LongMetric)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Arrays.stream (java.util.Arrays.stream)4 Collections.singleton (java.util.Collections.singleton)4 HashMap (java.util.HashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 TimeUnit (java.util.concurrent.TimeUnit)4