Search in sources :

Example 6 with LocalMemoryTracker

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

the class HeapTrackingLongIntHashMapTest 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 7 with LocalMemoryTracker

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

the class HeapTrackingUnifiedMapTest 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 8 with LocalMemoryTracker

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

the class HeapTrackingLongEnumerationListTest method addPutRemoveScenario.

@Test
void addPutRemoveScenario() {
    MemoryTracker memoryTracker = new LocalMemoryTracker();
    HeapTrackingLongEnumerationList<Long> table = HeapTrackingLongEnumerationList.create(memoryTracker, 4);
    assertEmpty(table);
    table.add(0L);
    table.put(2L, 2L);
    table.put(1L, 1L);
    assertContainsOnly(table, 0, 2);
    table.remove(0L);
    table.remove(1L);
    assertContainsOnly(table, 2);
    table.remove(2);
    assertEmpty(table);
    table.add(9999L);
    table.put(4L, 4L);
    // Replace
    assertEquals(table.put(3L, 3L), 9999L);
    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.put(6L, 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 and extra chunk allocated because of poor alignment in tail chunks
    table.put(8L, 8L);
    assertContainsOnly(table, new long[] { 3L, 6L, 8L });
    table.put(7L, 7L);
    assertContainsOnly(table, new long[] { 3L, 6L, 7L, 8L });
    table.remove(6L);
    assertContainsOnly(table, new long[] { 3L, 7L, 8L });
    table.remove(3L);
    assertContainsOnly(table, new long[] { 7L, 8L });
    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.put(10L, 10L);
    table.put(9L, 9L);
    table.add(11L);
    assertContainsOnly(table, 8, 11);
    table.remove(8L);
    table.remove(10L);
    table.remove(11L);
    assertContainsOnly(table, 9);
    table.put(12L, 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 9 with LocalMemoryTracker

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

the class MemoryAllocatorTest method trackMemoryAllocations.

@Test
void trackMemoryAllocations() {
    LocalMemoryTracker memoryTracker = new LocalMemoryTracker();
    GrabAllocator allocator = (GrabAllocator) MemoryAllocator.createAllocator(MebiByte.toBytes(2), memoryTracker);
    assertEquals(0, memoryTracker.usedNativeMemory());
    allocator.allocateAligned(ByteUnit.mebiBytes(1), 1);
    assertEquals(ByteUnit.mebiBytes(1), memoryTracker.usedNativeMemory());
    allocator.close();
    assertEquals(0, memoryTracker.usedNativeMemory());
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Test(org.junit.jupiter.api.Test)

Example 10 with LocalMemoryTracker

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

the class MutableLinearProbeLongHashSetTest method allocateFreeMemory.

@Test
void allocateFreeMemory() {
    final MemoryTracker memoryTrackerSpy = spy(new LocalMemoryTracker());
    final MutableLinearProbeLongHashSet set2 = new MutableLinearProbeLongHashSet(new OffHeapMemoryAllocator(blockAllocator), memoryTrackerSpy);
    verify(memoryTrackerSpy).allocateNative(anyLong());
    for (int i = 0; i < DEFAULT_CAPACITY; i++) {
        set2.add(100 + i);
    }
    verify(memoryTrackerSpy).releaseNative(anyLong());
    verify(memoryTrackerSpy, times(2)).allocateNative(anyLong());
    set2.close();
    verify(memoryTrackerSpy, times(2)).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