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);
}
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);
}
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);
}
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);
}
};
}
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());
}
Aggregations