Search in sources :

Example 1 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class TestQueryContext method testChecksTotalMemoryOnUserMemoryAllocation.

@Test(expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = ".*Query exceeded per-node total memory limit of 20B.*")
public void testChecksTotalMemoryOnUserMemoryAllocation() {
    try (LocalQueryRunner localQueryRunner = new LocalQueryRunner(TEST_SESSION)) {
        QueryContext queryContext = new QueryContext(new QueryId("query"), // user memory limit
        new DataSize(10, BYTE), // total memory limit
        new DataSize(20, BYTE), new DataSize(10, BYTE), new DataSize(1, GIGABYTE), new MemoryPool(GENERAL_POOL, new DataSize(10, BYTE)), new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(0, BYTE), new SpillSpaceTracker(new DataSize(0, BYTE)), listJsonCodec(TaskMemoryReservationSummary.class));
        queryContext.getQueryMemoryContext().initializeLocalMemoryContexts("test");
        LocalMemoryContext systemMemoryContext = queryContext.getQueryMemoryContext().localSystemMemoryContext();
        LocalMemoryContext userMemoryContext = queryContext.getQueryMemoryContext().localUserMemoryContext();
        systemMemoryContext.setBytes(15);
        userMemoryContext.setBytes(6);
    }
}
Also used : TaskMemoryReservationSummary(com.facebook.presto.operator.TaskMemoryReservationSummary) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) QueryId(com.facebook.presto.spi.QueryId) DataSize(io.airlift.units.DataSize) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Test(org.testng.annotations.Test)

Example 2 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class TestMemoryTracking method testLocalSystemAllocations.

@Test
public void testLocalSystemAllocations() {
    long pipelineLocalAllocation = 1_000_000;
    long taskLocalAllocation = 10_000_000;
    LocalMemoryContext pipelineLocalSystemMemoryContext = pipelineContext.localSystemMemoryContext();
    pipelineLocalSystemMemoryContext.setBytes(pipelineLocalAllocation);
    assertLocalMemoryAllocations(pipelineContext.getPipelineMemoryContext(), pipelineLocalAllocation, 0, pipelineLocalAllocation);
    LocalMemoryContext taskLocalSystemMemoryContext = taskContext.localSystemMemoryContext();
    taskLocalSystemMemoryContext.setBytes(taskLocalAllocation);
    assertLocalMemoryAllocations(taskContext.getTaskMemoryContext(), pipelineLocalAllocation + taskLocalAllocation, 0, taskLocalAllocation);
    assertEquals(pipelineContext.getPipelineStats().getSystemMemoryReservationInBytes(), pipelineLocalAllocation, "task level allocations should not be visible at the pipeline level");
    pipelineLocalSystemMemoryContext.setBytes(pipelineLocalSystemMemoryContext.getBytes() - pipelineLocalAllocation);
    assertLocalMemoryAllocations(pipelineContext.getPipelineMemoryContext(), taskLocalAllocation, 0, 0);
    taskLocalSystemMemoryContext.setBytes(taskLocalSystemMemoryContext.getBytes() - taskLocalAllocation);
    assertLocalMemoryAllocations(taskContext.getTaskMemoryContext(), 0, 0, 0);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Test(org.testng.annotations.Test)

Example 3 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

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(com.facebook.presto.memory.context.LocalMemoryContext) Test(org.testng.annotations.Test)

Example 4 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class TestMemoryTracking method testRevocableMemoryAllocations.

@Test
public void testRevocableMemoryAllocations() {
    LocalMemoryContext systemMemory = operatorContext.newLocalSystemMemoryContext("test");
    LocalMemoryContext userMemory = operatorContext.localUserMemoryContext();
    LocalMemoryContext revocableMemory = operatorContext.localRevocableMemoryContext();
    revocableMemory.setBytes(100_000_000);
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 0, 100_000_000, 0);
    userMemory.setBytes(100_000_000);
    systemMemory.setBytes(100_000_000);
    revocableMemory.setBytes(200_000_000);
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 200_000_000, 100_000_000);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Test(org.testng.annotations.Test)

Example 5 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

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(com.facebook.presto.memory.context.LocalMemoryContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test)

Aggregations

LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)31 Test (org.testng.annotations.Test)23 Page (com.facebook.presto.common.Page)8 QueryId (com.facebook.presto.spi.QueryId)6 Optional (java.util.Optional)6 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)5 Block (com.facebook.presto.common.block.Block)3 Type (com.facebook.presto.common.type.Type)3 DriverContext (com.facebook.presto.operator.DriverContext)3 OperatorContext (com.facebook.presto.operator.OperatorContext)3 Slice (io.airlift.slice.Slice)3 List (java.util.List)3 Supplier (java.util.function.Supplier)3 ClassLayout (org.openjdk.jol.info.ClassLayout)3 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)2 TestingTicker (com.facebook.airlift.testing.TestingTicker)2 ExceededMemoryLimitException (com.facebook.presto.ExceededMemoryLimitException)2 BlockAssertions (com.facebook.presto.block.BlockAssertions)2 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)2 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)2