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]);
}
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);
}
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)));
});
}
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")));
});
}
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();
}
}
Aggregations