Search in sources :

Example 1 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class PhysicalFlushableChannelTest method releaseBufferMemoryOnClose.

@Test
void releaseBufferMemoryOnClose() throws IOException {
    var memoryTracker = new LocalMemoryTracker();
    final Path firstFile = directory.homePath().resolve("file2");
    StoreChannel storeChannel = fileSystem.write(firstFile);
    PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, (byte) -1, firstFile, nativeChannelAccessor);
    assertThat(memoryTracker.estimatedHeapMemory()).isZero();
    assertThat(memoryTracker.usedNativeMemory()).isZero();
    try (PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel, memoryTracker)) {
        channel.put((byte) 1);
        assertThat(memoryTracker.usedNativeMemory()).isZero();
        assertThat(memoryTracker.estimatedHeapMemory()).isGreaterThan(0);
    }
    assertThat(memoryTracker.estimatedHeapMemory()).isZero();
    assertThat(memoryTracker.usedNativeMemory()).isZero();
}
Also used : Path(java.nio.file.Path) PhysicalFlushableChannel(org.neo4j.io.fs.PhysicalFlushableChannel) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 2 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class TxStateTest method before.

@BeforeEach
void before() {
    memoryTracker = new LocalMemoryTracker();
    collectionsFactory = spy(collectionsFactorySupplier.create());
    state = new TxState(collectionsFactory, memoryTracker);
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class UnsafeDirectByteBufferFactoryTest method shouldHandleMultipleClose.

@Test
void shouldHandleMultipleClose() {
    // given
    MemoryTracker tracker = new LocalMemoryTracker();
    UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator();
    // when
    factory.allocate(256, tracker);
    factory.close();
    // then
    assertEquals(0, tracker.usedNativeMemory());
    factory.close();
    assertEquals(0, tracker.usedNativeMemory());
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 4 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class UnsafeDirectByteBufferFactoryTest method shouldFreeOnClose.

@Test
void shouldFreeOnClose() {
    // given
    MemoryTracker tracker = new LocalMemoryTracker();
    try (UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator()) {
        // when
        factory.allocate(256, tracker);
    }
    // then
    assertEquals(0, tracker.usedNativeMemory());
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 5 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class ForsetiMemoryTrackingTest method concurrentMemoryShouldEndUpZero.

@Test
void concurrentMemoryShouldEndUpZero() throws Throwable {
    Race race = new Race();
    int numThreads = 4;
    LocalMemoryTracker[] trackers = new LocalMemoryTracker[numThreads];
    for (int i = 0; i < numThreads; i++) {
        trackers[i] = new LocalMemoryTracker(memoryPool);
        Locks.Client client = forsetiLockManager.newClient();
        client.initialize(LeaseService.NoLeaseClient.INSTANCE, 1, trackers[i], Config.defaults());
        race.addContestant(new SimulatedTransaction(client));
    }
    race.go();
    for (int i = 0; i < numThreads; i++) {
        try (LocalMemoryTracker tracker = trackers[i]) {
            assertThat(tracker.estimatedHeapMemory()).describedAs("Tracker " + tracker).isGreaterThanOrEqualTo(0);
        }
    }
}
Also used : Race(org.neo4j.test.Race) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Locks(org.neo4j.kernel.impl.locking.Locks) Test(org.junit.jupiter.api.Test)

Aggregations

LocalMemoryTracker (org.neo4j.memory.LocalMemoryTracker)30 Test (org.junit.jupiter.api.Test)19 BeforeEach (org.junit.jupiter.api.BeforeEach)9 MemoryPools (org.neo4j.memory.MemoryPools)8 MemoryTracker (org.neo4j.memory.MemoryTracker)7 ByteBuffer (java.nio.ByteBuffer)3 Path (java.nio.file.Path)2 EmptyMemoryTracker (org.neo4j.memory.EmptyMemoryTracker)2 Channel (io.netty.channel.Channel)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 BoltChannel (org.neo4j.bolt.BoltChannel)1 UnauthenticatedChannelProtector (org.neo4j.bolt.transport.pipeline.UnauthenticatedChannelProtector)1 UnsafeUtil.initDirectByteBuffer (org.neo4j.internal.unsafe.UnsafeUtil.initDirectByteBuffer)1 UnsafeUtil.newDirectByteBuffer (org.neo4j.internal.unsafe.UnsafeUtil.newDirectByteBuffer)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 PhysicalFlushableChannel (org.neo4j.io.fs.PhysicalFlushableChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 MemoryAllocator (org.neo4j.io.mem.MemoryAllocator)1 MuninnPageCache (org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)1 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)1