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