use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class CrashGenerationCleanerTest method tracePageCacheAccessInCleaners.
@Test
void tracePageCacheAccessInCleaners() throws IOException {
int numberOfPages = randomRule.intBetween(100, 1000);
Page[] pages = new Page[numberOfPages];
for (int i = 0; i < numberOfPages; i++) {
Page page = randomPage(0, new MutableInt());
pages[i] = page;
}
initializeFile(pagedFile, pages);
var cacheTracer = new DefaultPageCacheTracer();
assertThat(cacheTracer.pins()).isZero();
assertThat(cacheTracer.unpins()).isZero();
assertThat(cacheTracer.hits()).isZero();
var cleaner = new CrashGenerationCleaner(pagedFile, treeNode, 0, pages.length, unstableTreeState.stableGeneration(), unstableTreeState.unstableGeneration(), NO_MONITOR, cacheTracer, "test tree");
cleaner.clean(executor);
assertThat(cacheTracer.pins()).isEqualTo(pages.length);
assertThat(cacheTracer.unpins()).isEqualTo(pages.length);
assertThat(cacheTracer.hits()).isEqualTo(pages.length);
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class KernelStatementTest method emptyPageCacheStatisticOnClosedStatement.
@Test
void emptyPageCacheStatisticOnClosedStatement() {
var transaction = mock(KernelTransactionImplementation.class, RETURNS_DEEP_STUBS);
try (var statement = createStatement(transaction)) {
var cursorContext = new CursorContext(new DefaultPageCursorTracer(new DefaultPageCacheTracer(), "test"));
statement.initialize(Mockito.mock(Locks.Client.class), cursorContext, 100);
statement.acquire();
cursorContext.getCursorTracer().beginPin(false, 1, null).hit();
cursorContext.getCursorTracer().beginPin(false, 1, null).hit();
cursorContext.getCursorTracer().beginPin(false, 1, null).beginPageFault(1, 2).done();
assertEquals(2, statement.getHits());
assertEquals(1, statement.getFaults());
statement.close();
assertEquals(0, statement.getHits());
assertEquals(0, statement.getFaults());
}
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class PageCacheStressTesting method shouldBehaveCorrectlyUnderStress.
@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
int durationInMinutes = parseInt(fromEnv("PAGE_CACHE_STRESS_DURATION", "1"));
int numberOfPages = parseInt(fromEnv("PAGE_CACHE_STRESS_NUMBER_OF_PAGES", "10000"));
int numberOfThreads = parseInt(fromEnv("PAGE_CACHE_STRESS_NUMBER_OF_THREADS", "8"));
int numberOfCachePages = parseInt(fromEnv("PAGE_CACHE_STRESS_NUMBER_OF_CACHE_PAGES", "1000"));
File baseDir = new File(fromEnv("PAGE_CACHE_STRESS_WORKING_DIRECTORY", getProperty("java.io.tmpdir")));
File workingDirectory = new File(baseDir, "working");
DefaultPageCacheTracer monitor = new DefaultPageCacheTracer();
PageCacheStressTest runner = new PageCacheStressTest.Builder().with(timePeriod(durationInMinutes, MINUTES)).withNumberOfPages(numberOfPages).withNumberOfThreads(numberOfThreads).withNumberOfCachePages(numberOfCachePages).withWorkingDirectory(ensureExistsAndEmpty(workingDirectory)).with(monitor).build();
runner.run();
long faults = monitor.faults();
long evictions = monitor.evictions();
long pins = monitor.pins();
long unpins = monitor.unpins();
long flushes = monitor.flushes();
System.out.printf(" - page faults: %d%n - evictions: %d%n - pins: %d%n - unpins: %d%n - flushes: %d%n", faults, evictions, pins, unpins, flushes);
// let's cleanup disk space when everything went well
FileUtils.deleteRecursively(workingDirectory);
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class BatchingNeoStores method batchingNeoStores.
public static BatchingNeoStores batchingNeoStores(FileSystemAbstraction fileSystem, File storeDir, RecordFormats recordFormats, Configuration config, LogService logService, AdditionalInitialIds initialIds, Config dbConfig) {
Config neo4jConfig = getNeo4jConfig(config, dbConfig);
final PageCacheTracer tracer = new DefaultPageCacheTracer();
PageCache pageCache = createPageCache(fileSystem, neo4jConfig, logService.getInternalLogProvider(), tracer, DefaultPageCursorTracerSupplier.INSTANCE);
BatchingNeoStores batchingNeoStores = new BatchingNeoStores(fileSystem, pageCache, storeDir, recordFormats, neo4jConfig, logService, initialIds, false, tracer::bytesWritten);
return batchingNeoStores;
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class EncodingIdMapperTest method tracePageCacheAccessOnCollisions.
@Test
public void tracePageCacheAccessOnCollisions() {
EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
Encoder encoder = mock(Encoder.class);
when(encoder.encode(any())).thenReturn(12345L);
var pageCacheTracer = new DefaultPageCacheTracer();
IdMapper mapper = mapper(encoder, Radix.STRING, monitor, pageCacheTracer);
PropertyValueLookup ids = (nodeId, cursorContext) -> {
cursorContext.getCursorTracer().beginPin(false, 1, null).done();
return nodeId + "";
};
int expectedCollisions = 2;
for (int i = 0; i < expectedCollisions; i++) {
mapper.put(ids.lookupProperty(i, NULL), i, Group.GLOBAL);
}
ProgressListener progress = mock(ProgressListener.class);
Collector collector = mock(Collector.class);
mapper.prepare(ids, collector, progress);
verifyNoMoreInteractions(collector);
verify(monitor).numberOfCollisions(expectedCollisions);
assertEquals(expectedCollisions, pageCacheTracer.pins());
assertEquals(expectedCollisions, pageCacheTracer.unpins());
}
Aggregations