use of org.apache.ignite.internal.processors.metric.impl.LongAdderMetric in project ignite by apache.
the class BPlusTreeBenchmark method createPageMemory.
/**
* @return Page memory.
*/
private PageMemory createPageMemory() {
DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration().setMaxSize(1024 * MB);
DataRegionMetricsImpl dataRegionMetrics = mock(DataRegionMetricsImpl.class);
PageMetrics pageMetrics = mock(PageMetrics.class);
LongAdderMetric noOpMetric = new LongAdderMetric("foobar", null);
when(dataRegionMetrics.cacheGrpPageMetrics(anyInt())).thenReturn(pageMetrics);
when(pageMetrics.totalPages()).thenReturn(noOpMetric);
when(pageMetrics.indexPages()).thenReturn(noOpMetric);
PageMemory pageMem = new PageMemoryNoStoreImpl(new JavaLogger(), new UnsafeMemoryProvider(new JavaLogger()), null, PAGE_SIZE, dataRegionConfiguration, dataRegionMetrics, false);
pageMem.start();
return pageMem;
}
use of org.apache.ignite.internal.processors.metric.impl.LongAdderMetric in project ignite by apache.
the class PageMemoryImplTest method testCheckpointBufferCantOverflowWithThrottlingMixedLoad.
/**
* @throws Exception If failed.
*/
private void testCheckpointBufferCantOverflowWithThrottlingMixedLoad(PageMemoryImpl.ThrottlingPolicy plc) throws Exception {
PageMemoryImpl memory = createPageMemory(plc, null);
List<FullPageId> pages = new ArrayList<>();
for (int i = 0; i < (MAX_SIZE - 10) * MB / PAGE_SIZE / 2; i++) {
long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
FullPageId fullPageId = new FullPageId(pageId, 1);
pages.add(fullPageId);
acquireAndReleaseWriteLock(memory, fullPageId);
}
memory.beginCheckpoint(new GridFinishedFuture());
CheckpointMetricsTracker mockTracker = Mockito.mock(CheckpointMetricsTracker.class);
for (FullPageId checkpointPage : pages) memory.checkpointWritePage(checkpointPage, ByteBuffer.allocate(PAGE_SIZE), (fullPageId, buffer, tag) -> {
// No-op.
}, mockTracker);
memory.finishCheckpoint();
for (int i = (int) ((MAX_SIZE - 10) * MB / PAGE_SIZE / 2); i < (MAX_SIZE - 20) * MB / PAGE_SIZE; i++) {
long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
FullPageId fullPageId = new FullPageId(pageId, 1);
pages.add(fullPageId);
acquireAndReleaseWriteLock(memory, fullPageId);
}
memory.beginCheckpoint(new GridFinishedFuture());
// Mix pages in checkpoint with clean pages
Collections.shuffle(pages);
AtomicBoolean stop = new AtomicBoolean(false);
try {
GridTestUtils.runAsync(() -> {
for (FullPageId page : pages) {
if (// Mark dirty 50% of pages
ThreadLocalRandom.current().nextDouble() < 0.5)
try {
acquireAndReleaseWriteLock(memory, page);
if (stop.get())
break;
} catch (IgniteCheckedException e) {
log.error("runAsync ended with exception", e);
fail();
}
}
}).get(5_000);
} catch (IgniteFutureTimeoutCheckedException ignore) {
// Expected.
} finally {
stop.set(true);
}
memory.finishCheckpoint();
LongAdderMetric totalThrottlingTime = U.field(memory.metrics(), "totalThrottlingTime");
assertNotNull(totalThrottlingTime);
assertTrue(totalThrottlingTime.value() > 0);
}
use of org.apache.ignite.internal.processors.metric.impl.LongAdderMetric in project ignite by apache.
the class IndexMetricsTest method testIndexRebuildingMetric.
/**
* @throws Exception If failed.
*/
@Test
public void testIndexRebuildingMetric() throws Exception {
IgniteEx n = startGrid(0);
n.cluster().active(true);
String cacheName1 = "cache1";
String cacheName2 = "cache2";
IgniteCache<KeyClass, ValueClass> cache1 = n.getOrCreateCache(cacheConfiguration(cacheName1));
IgniteCache<KeyClass, ValueClass> cache2 = n.getOrCreateCache(cacheConfiguration(cacheName2));
int entryCnt1 = 100;
int entryCnt2 = 200;
for (int i = 0; i < entryCnt1; i++) cache1.put(new KeyClass(i), new ValueClass((long) i));
for (int i = 0; i < entryCnt2; i++) cache2.put(new KeyClass(i), new ValueClass((long) i));
List<Path> idxPaths = getIndexBinPaths(cacheName1);
idxPaths.addAll(getIndexBinPaths(cacheName2));
stopAllGrids();
idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
n = startGrid(0);
BooleanMetric idxRebuildInProgress1 = indexRebuildMetric(n, cacheName1, "IsIndexRebuildInProgress");
BooleanMetric idxRebuildInProgress2 = indexRebuildMetric(n, cacheName2, "IsIndexRebuildInProgress");
LongAdderMetric idxRebuildKeyProcessed1 = indexRebuildMetric(n, cacheName1, "IndexRebuildKeyProcessed");
LongAdderMetric idxRebuildKeyProcessed2 = indexRebuildMetric(n, cacheName2, "IndexRebuildKeyProcessed");
CacheMetrics cacheMetrics1 = cacheMetrics(n, cacheName1);
CacheMetrics cacheMetrics2 = cacheMetrics(n, cacheName2);
CacheMetricsMXBean cacheMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheLocalMetricsMXBeanImpl.class);
CacheMetricsMXBean cacheMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheLocalMetricsMXBeanImpl.class);
CacheMetricsMXBean cacheClusterMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheClusterMetricsMXBeanImpl.class);
CacheMetricsMXBean cacheClusterMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheClusterMetricsMXBeanImpl.class);
n.cluster().active(true);
BooleanSupplier[] idxRebuildProgressCache1 = { idxRebuildInProgress1::value, cacheMetrics1::isIndexRebuildInProgress, cacheMetricsMXBean1::isIndexRebuildInProgress };
BooleanSupplier[] idxRebuildProgressCache2 = { idxRebuildInProgress2::value, cacheMetrics2::isIndexRebuildInProgress, cacheMetricsMXBean2::isIndexRebuildInProgress };
// It must always be false, because metric is only per node.
BooleanSupplier[] idxRebuildProgressCluster = { cacheClusterMetricsMXBean1::isIndexRebuildInProgress, cacheClusterMetricsMXBean2::isIndexRebuildInProgress };
LongSupplier[] idxRebuildKeyProcessedCache1 = { idxRebuildKeyProcessed1::value, cacheMetrics1::getIndexRebuildKeysProcessed, cacheMetricsMXBean1::getIndexRebuildKeysProcessed };
LongSupplier[] idxRebuildKeyProcessedCache2 = { idxRebuildKeyProcessed2::value, cacheMetrics2::getIndexRebuildKeysProcessed, cacheMetricsMXBean2::getIndexRebuildKeysProcessed };
// It must always be 0, because metric is only per node.
LongSupplier[] idxRebuildKeyProcessedCluster = { cacheClusterMetricsMXBean1::getIndexRebuildKeysProcessed, cacheClusterMetricsMXBean2::getIndexRebuildKeysProcessed };
assertEquals(true, idxRebuildProgressCache1);
assertEquals(true, idxRebuildProgressCache2);
assertEquals(false, idxRebuildProgressCluster);
assertEquals(0, idxRebuildKeyProcessedCache1);
assertEquals(0, idxRebuildKeyProcessedCache2);
assertEquals(0, idxRebuildKeyProcessedCluster);
((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName1);
n.cache(cacheName1).indexReadyFuture().get(30_000);
assertEquals(false, idxRebuildProgressCache1);
assertEquals(true, idxRebuildProgressCache2);
assertEquals(false, idxRebuildProgressCluster);
assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
assertEquals(0, idxRebuildKeyProcessedCache2);
assertEquals(0, idxRebuildKeyProcessedCluster);
((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName2);
n.cache(cacheName2).indexReadyFuture().get(30_000);
assertEquals(false, idxRebuildProgressCache1);
assertEquals(false, idxRebuildProgressCache2);
assertEquals(false, idxRebuildProgressCluster);
assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
assertEquals(entryCnt2, idxRebuildKeyProcessedCache2);
assertEquals(0, idxRebuildKeyProcessedCluster);
}
use of org.apache.ignite.internal.processors.metric.impl.LongAdderMetric in project ignite by apache.
the class TcpCommunicationStatisticsTest method testStatistics.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("ConstantConditions")
@Test
public void testStatistics() throws Exception {
startGrids(2);
try {
Object node0consistentId = grid(0).localNode().consistentId();
Object node1consistentId = grid(1).localNode().consistentId();
String node0regName = MetricUtils.metricName(COMMUNICATION_METRICS_GROUP_NAME, node0consistentId.toString());
String node1regName = MetricUtils.metricName(COMMUNICATION_METRICS_GROUP_NAME, node1consistentId.toString());
// Send custom message from node0 to node1.
grid(0).context().io().sendToGridTopic(grid(1).cluster().localNode(), GridTopic.TOPIC_IO_TEST, new GridTestMessage(), GridIoPolicy.PUBLIC_POOL);
latch.await(10, TimeUnit.SECONDS);
ClusterGroup clusterGrpNode1 = grid(0).cluster().forNodeId(grid(1).localNode().id());
// Send job from node0 to node1.
grid(0).compute(clusterGrpNode1).call(new IgniteCallable<Boolean>() {
@Override
public Boolean call() throws Exception {
return Boolean.TRUE;
}
});
synchronized (mux) {
TcpCommunicationSpiMBean mbean0 = mbean(0);
TcpCommunicationSpiMBean mbean1 = mbean(1);
Map<UUID, Long> msgsSentByNode0 = mbean0.getSentMessagesByNode();
Map<UUID, Long> msgsSentByNode1 = mbean1.getSentMessagesByNode();
Map<UUID, Long> msgsReceivedByNode0 = mbean0.getReceivedMessagesByNode();
Map<UUID, Long> msgsReceivedByNode1 = mbean1.getReceivedMessagesByNode();
UUID nodeId0 = grid(0).localNode().id();
UUID nodeId1 = grid(1).localNode().id();
assertEquals(msgsReceivedByNode0.get(nodeId1).longValue(), mbean0.getReceivedMessagesCount());
assertEquals(msgsReceivedByNode1.get(nodeId0).longValue(), mbean1.getReceivedMessagesCount());
assertEquals(msgsSentByNode0.get(nodeId1).longValue(), mbean0.getSentMessagesCount());
assertEquals(msgsSentByNode1.get(nodeId0).longValue(), mbean1.getSentMessagesCount());
assertEquals(mbean0.getSentMessagesCount(), mbean1.getReceivedMessagesCount());
assertEquals(mbean1.getSentMessagesCount(), mbean0.getReceivedMessagesCount());
Map<String, Long> msgsSentByType0 = mbean0.getSentMessagesByType();
Map<String, Long> msgsSentByType1 = mbean1.getSentMessagesByType();
Map<String, Long> msgsReceivedByType0 = mbean0.getReceivedMessagesByType();
Map<String, Long> msgsReceivedByType1 = mbean1.getReceivedMessagesByType();
// Node0 sent exactly the same types and count of messages as node1 received.
assertEquals(msgsSentByType0, msgsReceivedByType1);
// Node1 sent exactly the same types and count of messages as node0 received.
assertEquals(msgsSentByType1, msgsReceivedByType0);
assertEquals(1, msgsSentByType0.get(GridTestMessage.class.getName()).longValue());
assertEquals(1, msgsReceivedByType1.get(GridTestMessage.class.getName()).longValue());
MetricRegistry mreg0 = grid(0).context().metric().registry(node1regName);
MetricRegistry mreg1 = grid(1).context().metric().registry(node0regName);
LongAdderMetric sentMetric = mreg0.findMetric(SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
assertNotNull(sentMetric);
assertEquals(mbean0.getSentMessagesCount(), sentMetric.value());
LongAdderMetric rcvMetric = mreg1.findMetric(RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
assertNotNull(rcvMetric);
assertEquals(mbean1.getReceivedMessagesCount(), rcvMetric.value());
stopGrid(1);
mreg0 = grid(0).context().metric().registry(node1regName);
sentMetric = mreg0.findMetric(SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
// Automatically generated by MetricRegistryCreationListener.
assertNotNull(sentMetric);
assertEquals(0, sentMetric.value());
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.processors.metric.impl.LongAdderMetric 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();
}
}
Aggregations