Search in sources :

Example 21 with LocalMemoryTracker

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

the class HeapTrackingUnifiedSetTest method setUp.

@BeforeEach
void setUp() {
    memoryPool = new MemoryPools().pool(MemoryGroup.TRANSACTION, 0L, null);
    memoryTracker = new LocalMemoryTracker(memoryPool);
}
Also used : MemoryPools(org.neo4j.memory.MemoryPools) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with LocalMemoryTracker

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

the class HeapTrackingIntObjectHashMapTest method setUp.

@BeforeEach
void setUp() {
    memoryPool = new MemoryPools().pool(MemoryGroup.TRANSACTION, 0L, null);
    memoryTracker = new LocalMemoryTracker(memoryPool);
}
Also used : MemoryPools(org.neo4j.memory.MemoryPools) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with LocalMemoryTracker

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

the class UnsafeUtilTest method directByteBufferCreationAndInitialisation.

@Test
void directByteBufferCreationAndInitialisation() throws Throwable {
    int sizeInBytes = 313;
    var tracker = new LocalMemoryTracker();
    long address = allocateMemory(sizeInBytes, tracker);
    try {
        setMemory(address, sizeInBytes, (byte) 0);
        ByteBuffer a = newDirectByteBuffer(address, sizeInBytes);
        assertThat(a).isNotSameAs(newDirectByteBuffer(address, sizeInBytes));
        assertThat(a.hasArray()).isEqualTo(false);
        assertThat(a.isDirect()).isEqualTo(true);
        assertThat(a.capacity()).isEqualTo(sizeInBytes);
        assertThat(a.limit()).isEqualTo(sizeInBytes);
        assertThat(a.position()).isEqualTo(0);
        assertThat(a.remaining()).isEqualTo(sizeInBytes);
        assertThat(getByte(address)).isEqualTo((byte) 0);
        a.put((byte) -1);
        assertThat(getByte(address)).isEqualTo((byte) -1);
        a.position(101);
        a.mark();
        a.limit(202);
        int sizeInBytes2 = 424;
        long address2 = allocateMemory(sizeInBytes2, tracker);
        try {
            setMemory(address2, sizeInBytes2, (byte) 0);
            initDirectByteBuffer(a, address2, sizeInBytes2);
            assertThat(a.hasArray()).isEqualTo(false);
            assertThat(a.isDirect()).isEqualTo(true);
            assertThat(a.capacity()).isEqualTo(sizeInBytes2);
            assertThat(a.limit()).isEqualTo(sizeInBytes2);
            assertThat(a.position()).isEqualTo(0);
            assertThat(a.remaining()).isEqualTo(sizeInBytes2);
            assertThat(getByte(address2)).isEqualTo((byte) 0);
            a.put((byte) -1);
            assertThat(getByte(address2)).isEqualTo((byte) -1);
        } finally {
            free(address2, sizeInBytes2, tracker);
        }
    } finally {
        free(address, sizeInBytes, tracker);
    }
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) UnsafeUtil.initDirectByteBuffer(org.neo4j.internal.unsafe.UnsafeUtil.initDirectByteBuffer) ByteBuffer(java.nio.ByteBuffer) UnsafeUtil.newDirectByteBuffer(org.neo4j.internal.unsafe.UnsafeUtil.newDirectByteBuffer) Test(org.junit.jupiter.api.Test)

Example 24 with LocalMemoryTracker

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

the class HeapTrackingLongEnumerationListTest method addRemoveScenario.

@Test
void addRemoveScenario() {
    MemoryTracker memoryTracker = new LocalMemoryTracker();
    HeapTrackingLongEnumerationList<Long> table = HeapTrackingLongEnumerationList.create(memoryTracker, 4);
    assertEmpty(table);
    table.add(0L);
    table.add(1L);
    table.add(2L);
    assertContainsOnly(table, 0, 2);
    table.remove(0L);
    table.remove(1L);
    assertContainsOnly(table, 2);
    table.remove(2);
    assertEmpty(table);
    table.add(3L);
    table.add(4L);
    table.add(5L);
    assertContainsOnly(table, 3, 5);
    table.remove(5);
    assertContainsOnly(table, 3, 4);
    table.remove(4);
    assertContainsOnly(table, 3);
    long measured1 = meter.measureDeep(table) - measuredMemoryTracker;
    assertEquals(measured1, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
    table.add(6L);
    assertContainsOnly(table, new long[] { 3L, 6L });
    long measured2 = meter.measureDeep(table) - measuredMemoryTracker;
    assertEquals(measured2, memoryTracker.estimatedHeapMemory() + 2 * HeapEstimator.LONG_SIZE);
    assertEquals(HeapEstimator.LONG_SIZE, measured2 - measured1);
    // New chunk needed
    table.add(7L);
    assertContainsOnly(table, new long[] { 3L, 6, 7L });
    // New chunk allocated because of poor alignment in tail chunks
    table.add(8L);
    assertContainsOnly(table, new long[] { 3L, 6L, 7L, 8L });
    table.remove(6L);
    assertContainsOnly(table, new long[] { 3L, 7L, 8L });
    // Should recycle chunk
    table.remove(3L);
    assertContainsOnly(table, new long[] { 7L, 8L });
    // Should recycle chunk
    table.remove(7L);
    assertContainsOnly(table, 8L);
    // Memory should be back to one chunk + one value
    long measured3 = meter.measureDeep(table) - measuredMemoryTracker;
    assertEquals(measured3, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
    assertEquals(measured1, measured3);
    table.add(9L);
    table.add(10L);
    table.add(11L);
    assertContainsOnly(table, 8, 11);
    table.remove(8L);
    table.remove(10L);
    table.remove(11L);
    assertContainsOnly(table, 9);
    table.add(12L);
    assertContainsOnly(table, new long[] { 9L, 12L });
    table.remove(9L);
    assertContainsOnly(table, 12);
    // Memory should be one chunk + one value
    long measured4 = meter.measureDeep(table) - measuredMemoryTracker;
    assertEquals(measured4, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
    assertEquals(measured3, measured4);
    table.close();
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 25 with LocalMemoryTracker

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

the class MutableLinearProbeLongHashSetTest method freeFrozenMemory.

@Test
void freeFrozenMemory() {
    final MemoryTracker memoryTrackerSpy = spy(new LocalMemoryTracker());
    final MutableLinearProbeLongHashSet set2 = new MutableLinearProbeLongHashSet(new OffHeapMemoryAllocator(blockAllocator), memoryTrackerSpy);
    verify(memoryTrackerSpy).allocateNative(anyLong());
    set2.addAll(100, 200, 300);
    set2.freeze();
    set2.remove(100);
    set2.freeze();
    set2.clear();
    set2.close();
    verify(memoryTrackerSpy, times(3)).releaseNative(anyLong());
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) EmptyMemoryTracker(org.neo4j.memory.EmptyMemoryTracker) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) 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