Search in sources :

Example 11 with LocalMemoryTracker

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

the class RecentQueryBufferTest method shouldEstimateHeapOfFilledEmptiedBuffer.

@Test
void shouldEstimateHeapOfFilledEmptiedBuffer() {
    // given
    LocalMemoryTracker memoryTracker = new LocalMemoryTracker();
    RecentQueryBuffer buffer = new RecentQueryBuffer(4, memoryTracker);
    // when
    var queries = new TruncatedQuerySnapshot[] { query("RETURN 1", EMPTY_MAP), query("RETURN 2", EMPTY_MAP), query("RETURN 3", EMPTY_MAP), query("RETURN 4", EMPTY_MAP) };
    for (TruncatedQuerySnapshot q : queries) {
        buffer.produce(q);
    }
    buffer.clear(DATABASE_ID);
    // then
    assertEstimatedMemory(memoryTracker, buffer);
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Test(org.junit.jupiter.api.Test)

Example 12 with LocalMemoryTracker

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

the class RecentQueryBufferTest method shouldEstimateHeapOfAddedQuery.

@Test
void shouldEstimateHeapOfAddedQuery() {
    // given
    LocalMemoryTracker memoryTracker = new LocalMemoryTracker();
    RecentQueryBuffer buffer = new RecentQueryBuffer(4, memoryTracker);
    // when
    var q = query("RETURN 1", EMPTY_MAP);
    buffer.produce(q);
    // then
    assertEstimatedMemory(memoryTracker, buffer, q);
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Test(org.junit.jupiter.api.Test)

Example 13 with LocalMemoryTracker

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

the class RecentQueryBufferTest method shouldEstimateHeapOfEmptyBuffer.

@Test
void shouldEstimateHeapOfEmptyBuffer() {
    // when
    LocalMemoryTracker memoryTracker = new LocalMemoryTracker();
    RecentQueryBuffer buffer = new RecentQueryBuffer(4, memoryTracker);
    // then
    assertEstimatedMemory(memoryTracker, buffer);
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Test(org.junit.jupiter.api.Test)

Example 14 with LocalMemoryTracker

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

the class SocketTransport method channelInitializer.

@Override
public ChannelInitializer<Channel> channelInitializer() {
    return new ChannelInitializer<>() {

        @Override
        public void initChannel(Channel ch) {
            ch.config().setAllocator(allocator);
            var memoryTracker = new LocalMemoryTracker(memoryPool, 0, 64, null);
            ch.closeFuture().addListener(future -> memoryTracker.close());
            memoryTracker.allocateHeap(HeapEstimator.sizeOf(ch));
            memoryTracker.allocateHeap(UnauthenticatedChannelProtector.SHALLOW_SIZE + BoltChannel.SHALLOW_SIZE);
            var channelProtector = new UnauthenticatedChannelProtector(ch, channelTimeout, maxMessageSize, memoryTracker);
            BoltChannel boltChannel = newBoltChannel(ch, channelProtector, memoryTracker);
            connectionTracker.add(boltChannel);
            ch.closeFuture().addListener(future -> connectionTracker.remove(boltChannel));
            // install throttles
            throttleGroup.install(ch, memoryTracker);
            // add a close listener that will uninstall throttles
            ch.closeFuture().addListener(future -> throttleGroup.uninstall(ch));
            memoryTracker.allocateHeap(TransportSelectionHandler.SHALLOW_SIZE);
            TransportSelectionHandler transportSelectionHandler = new TransportSelectionHandler(boltChannel, sslCtx, encryptionRequired, false, logging, boltProtocolFactory, channelProtector, memoryTracker);
            ch.pipeline().addLast(transportSelectionHandler);
        }
    };
}
Also used : UnauthenticatedChannelProtector(org.neo4j.bolt.transport.pipeline.UnauthenticatedChannelProtector) BoltChannel(org.neo4j.bolt.BoltChannel) Channel(io.netty.channel.Channel) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) BoltChannel(org.neo4j.bolt.BoltChannel) ChannelInitializer(io.netty.channel.ChannelInitializer)

Example 15 with LocalMemoryTracker

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

the class NumberArrayFactoryTest method trackHeapMemoryAllocations.

@Test
void trackHeapMemoryAllocations() {
    var memoryTracker = new LocalMemoryTracker(MemoryPools.NO_TRACKING, 300, 0, null);
    HEAP.newByteArray(10, new byte[] { 0 }, memoryTracker);
    assertEquals(32, memoryTracker.estimatedHeapMemory());
    assertEquals(0, memoryTracker.usedNativeMemory());
    memoryTracker = new LocalMemoryTracker(MemoryPools.NO_TRACKING, 300, 0, null);
    HEAP.newLongArray(10, 1, memoryTracker);
    assertEquals(96, memoryTracker.estimatedHeapMemory());
    assertEquals(0, memoryTracker.usedNativeMemory());
    memoryTracker = new LocalMemoryTracker(MemoryPools.NO_TRACKING, 300, 0, null);
    HEAP.newIntArray(10, 1, memoryTracker);
    assertEquals(56, memoryTracker.estimatedHeapMemory());
    assertEquals(0, memoryTracker.usedNativeMemory());
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) 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