Search in sources :

Example 1 with LocalMemoryContext

use of io.prestosql.memory.context.LocalMemoryContext in project hetu-core by openlookeng.

the class ParquetReader method allocateBlock.

private byte[] allocateBlock(int length) {
    byte[] buffer = new byte[length];
    LocalMemoryContext blockMemoryContext = currentRowGroupMemoryContext.newLocalMemoryContext(ParquetReader.class.getSimpleName());
    blockMemoryContext.setBytes(buffer.length);
    return buffer;
}
Also used : LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext)

Example 2 with LocalMemoryContext

use of io.prestosql.memory.context.LocalMemoryContext in project hetu-core by openlookeng.

the class TestOperatorMemoryRevocation method testOperatorMemoryRevocation.

@Test
public void testOperatorMemoryRevocation() {
    AtomicInteger counter = new AtomicInteger();
    OperatorContext operatorContext = TestingOperatorContext.create(scheduledExecutor);
    LocalMemoryContext revocableMemoryContext = operatorContext.localRevocableMemoryContext();
    revocableMemoryContext.setBytes(1000);
    operatorContext.setMemoryRevocationRequestListener(() -> counter.incrementAndGet());
    operatorContext.requestMemoryRevoking();
    assertTrue(operatorContext.isMemoryRevokingRequested());
    assertEquals(counter.get(), 1);
    // calling resetMemoryRevokingRequested() should clear the memory revoking requested flag
    operatorContext.resetMemoryRevokingRequested();
    assertFalse(operatorContext.isMemoryRevokingRequested());
    operatorContext.requestMemoryRevoking();
    assertEquals(counter.get(), 2);
    assertTrue(operatorContext.isMemoryRevokingRequested());
}
Also used : LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test)

Example 3 with LocalMemoryContext

use of io.prestosql.memory.context.LocalMemoryContext in project hetu-core by openlookeng.

the class TestOperatorMemoryRevocation method testRevocationAlreadyRequested.

@Test
public void testRevocationAlreadyRequested() {
    AtomicInteger counter = new AtomicInteger();
    OperatorContext operatorContext = TestingOperatorContext.create(scheduledExecutor);
    LocalMemoryContext revocableMemoryContext = operatorContext.localRevocableMemoryContext();
    revocableMemoryContext.setBytes(1000);
    // when memory revocation is already requested setting a listener should immediately execute it
    operatorContext.requestMemoryRevoking();
    operatorContext.setMemoryRevocationRequestListener(() -> counter.incrementAndGet());
    assertTrue(operatorContext.isMemoryRevokingRequested());
    assertEquals(counter.get(), 1);
}
Also used : LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test)

Example 4 with LocalMemoryContext

use of io.prestosql.memory.context.LocalMemoryContext in project hetu-core by openlookeng.

the class TestMemoryTracking method testDestroy.

@Test
public void testDestroy() {
    LocalMemoryContext newLocalSystemMemoryContext = operatorContext.newLocalSystemMemoryContext("test");
    LocalMemoryContext newLocalUserMemoryContext = operatorContext.localUserMemoryContext();
    LocalMemoryContext newLocalRevocableMemoryContext = operatorContext.localRevocableMemoryContext();
    newLocalSystemMemoryContext.setBytes(100_000);
    newLocalRevocableMemoryContext.setBytes(200_000);
    newLocalUserMemoryContext.setBytes(400_000);
    assertEquals(operatorContext.getOperatorMemoryContext().getSystemMemory(), 100_000);
    assertEquals(operatorContext.getOperatorMemoryContext().getUserMemory(), 400_000);
    operatorContext.destroy();
    assertOperatorMemoryAllocations(operatorContext.getOperatorMemoryContext(), 0, 0, 0);
}
Also used : LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) Test(org.testng.annotations.Test)

Example 5 with LocalMemoryContext

use of io.prestosql.memory.context.LocalMemoryContext in project hetu-core by openlookeng.

the class TestMemoryTracking method testTrySetBytes.

@Test
public void testTrySetBytes() {
    LocalMemoryContext localMemoryContext = operatorContext.localUserMemoryContext();
    assertTrue(localMemoryContext.trySetBytes(100_000_000));
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 0, 0);
    assertTrue(localMemoryContext.trySetBytes(200_000_000));
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 200_000_000, 0, 0);
    assertTrue(localMemoryContext.trySetBytes(100_000_000));
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 0, 0);
    // allocating more than the pool size should fail and we should have the same stats as before
    assertFalse(localMemoryContext.trySetBytes(memoryPool.getMaxBytes() + 1));
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 0, 0);
}
Also used : LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) Test(org.testng.annotations.Test)

Aggregations

LocalMemoryContext (io.prestosql.memory.context.LocalMemoryContext)23 Test (org.testng.annotations.Test)18 Page (io.prestosql.spi.Page)9 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)5 Optional (java.util.Optional)5 SerializedPage (io.hetu.core.transport.execution.buffer.SerializedPage)4 Iterator (java.util.Iterator)4 QueryId (io.prestosql.spi.QueryId)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ImmutableList (com.google.common.collect.ImmutableList)2 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)2 Slice (io.airlift.slice.Slice)2 Slices (io.airlift.slice.Slices)2 TestingTicker (io.airlift.testing.TestingTicker)2 DataSize (io.airlift.units.DataSize)2 Duration (io.airlift.units.Duration)2 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)2 BlockAssertions.createSlicesBlock (io.prestosql.block.BlockAssertions.createSlicesBlock)2 BlockAssertions.createStringsBlock (io.prestosql.block.BlockAssertions.createStringsBlock)2 SPLIT_RUN_QUANTA (io.prestosql.execution.executor.PrioritizedSplitRunner.SPLIT_RUN_QUANTA)2