use of org.neo4j.io.pagecache.impl.muninn.MuninnPageCache in project neo4j by neo4j.
the class ConfiguringPageCacheFactory method createPageCache.
protected PageCache createPageCache() {
long pageCacheMaxMemory = getPageCacheMaxMemory(config);
var memoryPool = memoryPools.pool(PAGE_CACHE, pageCacheMaxMemory, false, null);
var memoryTracker = memoryPool.getPoolMemoryTracker();
MemoryAllocator memoryAllocator = buildMemoryAllocator(pageCacheMaxMemory, memoryTracker);
var bufferFactory = new ConfigurableIOBufferFactory(config, memoryTracker);
MuninnPageCache.Configuration configuration = MuninnPageCache.config(memoryAllocator).memoryTracker(memoryTracker).bufferFactory(bufferFactory).preallocateStoreFiles(config.get(preallocate_store_files)).clock(clock).pageCacheTracer(pageCacheTracer);
return new MuninnPageCache(swapperFactory, scheduler, configuration);
}
use of org.neo4j.io.pagecache.impl.muninn.MuninnPageCache in project neo4j by neo4j.
the class PageCacheRule method getPageCache.
/**
* Opens a new {@link PageCache} with the provided file system and config.
*
* @param factory {@link PageSwapperFactory} to use for the {@link PageCache}.
* @param overriddenConfig specific {@link PageCacheConfig} overriding config provided in {@link PageCacheRule}
* constructor, if any.
* @return the opened {@link PageCache}.
*/
public PageCache getPageCache(PageSwapperFactory factory, PageCacheConfig overriddenConfig) {
closeExistingPageCache();
var memoryTracker = new LocalMemoryTracker();
MemoryAllocator mman = MemoryAllocator.createAllocator(parse(selectConfig(baseConfig.memory, overriddenConfig.memory, "8 MiB")), memoryTracker);
if (clock == null) {
clock = Clocks.nanoClock();
}
MuninnPageCache.Configuration configuration = MuninnPageCache.config(mman).memoryTracker(memoryTracker).clock(clock);
Integer pageSize = selectConfig(baseConfig.pageSize, overriddenConfig.pageSize, null);
configuration = pageSize == null ? configuration : configuration.pageSize(pageSize);
PageCacheTracer cacheTracer = selectConfig(baseConfig.tracer, overriddenConfig.tracer, PageCacheTracer.NULL);
configuration = configuration.pageCacheTracer(cacheTracer);
initializeJobScheduler();
pageCache = new MuninnPageCache(factory, jobScheduler, configuration);
pageCachePostConstruct(overriddenConfig);
return pageCache;
}
use of org.neo4j.io.pagecache.impl.muninn.MuninnPageCache in project neo4j by neo4j.
the class PageCacheStressTest method run.
public void run() throws Exception {
try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fs);
try (PageCache pageCacheUnderTest = new MuninnPageCache(swapperFactory, jobScheduler, config(numberOfCachePages).pageCacheTracer(tracer))) {
PageCacheStresser pageCacheStresser = new PageCacheStresser(numberOfPages, numberOfThreads, workingDirectory);
pageCacheStresser.stress(pageCacheUnderTest, tracer, condition);
}
}
}
use of org.neo4j.io.pagecache.impl.muninn.MuninnPageCache in project neo4j by neo4j.
the class RandomPageCacheTestHarness method runIteration.
@SuppressWarnings("unchecked")
private void runIteration(long timeout, TimeUnit unit) throws Exception {
assert filePageSize % recordFormat.getRecordSize() == 0 : "File page size must be a multiple of the record size";
if (!fixedRandomSeed) {
randomSeed = ThreadLocalRandom.current().nextLong();
}
FileSystemAbstraction fs = this.fs;
Path[] files = buildFileNames();
RandomAdversary adversary = new RandomAdversary(mischiefRate, failureRate, errorRate);
adversary.setProbabilityFactor(0.0);
if (useAdversarialIO) {
adversary.setSeed(randomSeed);
fs = new AdversarialFileSystemAbstraction(adversary, fs);
}
PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fs);
JobScheduler jobScheduler = new ThreadPoolJobScheduler();
MuninnPageCache cache = new MuninnPageCache(swapperFactory, jobScheduler, MuninnPageCache.config(cachePageCount).pageCacheTracer(tracer));
if (filePageSize == 0) {
filePageSize = cache.pageSize();
}
cache.setPrintExceptionsOnClose(false);
Map<Path, PagedFile> fileMap = new HashMap<>(files.length);
for (int i = 0; i < Math.min(files.length, initialMappedFiles); i++) {
Path file = files[i];
fileMap.put(file, cache.map(file, filePageSize, DEFAULT_DATABASE_NAME));
}
plan = plan(cache, files, fileMap);
AtomicBoolean stopSignal = new AtomicBoolean();
Callable<Void> planRunner = new PlanRunner(plan, stopSignal, profiler);
Future<Void>[] futures = new Future[concurrencyLevel];
for (int i = 0; i < concurrencyLevel; i++) {
futures[i] = executorService.submit(planRunner);
}
if (preparation != null) {
preparation.run(cache, this.fs, plan.getFilesTouched());
}
adversary.setProbabilityFactor(1.0);
plan.start();
long deadlineMillis = System.currentTimeMillis() + unit.toMillis(timeout);
long now;
try {
for (Future<Void> future : futures) {
now = System.currentTimeMillis();
if (deadlineMillis < now) {
throw new TimeoutException();
}
future.get(deadlineMillis - now, TimeUnit.MILLISECONDS);
}
adversary.setProbabilityFactor(0.0);
runVerificationPhase(cache);
} finally {
stopSignal.set(true);
adversary.setProbabilityFactor(0.0);
try {
for (Future<Void> future : futures) {
future.get(10, TimeUnit.SECONDS);
}
} catch (InterruptedException | TimeoutException e) {
for (Future<Void> future : futures) {
future.cancel(true);
}
throw new RuntimeException(e);
}
try {
plan.close();
cache.close();
jobScheduler.close();
if (this.fs instanceof EphemeralFileSystemAbstraction) {
this.fs.close();
this.fs = new EphemeralFileSystemAbstraction();
} else {
for (Path file : files) {
Files.delete(file);
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Aggregations