Search in sources :

Example 21 with LocalMemoryContext

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

the class TestMemoryTracking method testOperatorAllocations.

@Test
public void testOperatorAllocations() {
    MemoryTrackingContext operatorMemoryContext = operatorContext.getOperatorMemoryContext();
    LocalMemoryContext systemMemory = operatorContext.newLocalSystemMemoryContext("test");
    LocalMemoryContext userMemory = operatorContext.localUserMemoryContext();
    LocalMemoryContext revocableMemory = operatorContext.localRevocableMemoryContext();
    userMemory.setBytes(100);
    assertOperatorMemoryAllocations(operatorMemoryContext, 100, 0, 0);
    systemMemory.setBytes(1_000_000);
    assertOperatorMemoryAllocations(operatorMemoryContext, 100, 1_000_000, 0);
    systemMemory.setBytes(2_000_000);
    assertOperatorMemoryAllocations(operatorMemoryContext, 100, 2_000_000, 0);
    userMemory.setBytes(500);
    assertOperatorMemoryAllocations(operatorMemoryContext, 500, 2_000_000, 0);
    userMemory.setBytes(userMemory.getBytes() - 500);
    assertOperatorMemoryAllocations(operatorMemoryContext, 0, 2_000_000, 0);
    revocableMemory.setBytes(300);
    assertOperatorMemoryAllocations(operatorMemoryContext, 0, 2_000_000, 300);
    assertAllocationFails((ignored) -> userMemory.setBytes(userMemory.getBytes() - 500), "bytes cannot be negative");
    operatorContext.destroy();
    assertOperatorMemoryAllocations(operatorMemoryContext, 0, 0, 0);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) MemoryTrackingContext(com.facebook.presto.memory.context.MemoryTrackingContext) Test(org.testng.annotations.Test)

Example 22 with LocalMemoryContext

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

the class TestMemoryTracking method testStats.

@Test
public void testStats() {
    LocalMemoryContext systemMemory = operatorContext.newLocalSystemMemoryContext("test");
    LocalMemoryContext userMemory = operatorContext.localUserMemoryContext();
    userMemory.setBytes(100_000_000);
    systemMemory.setBytes(200_000_000);
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 0, 200_000_000);
    // allocate more and check peak memory reservation
    userMemory.setBytes(600_000_000);
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 600_000_000, 0, 200_000_000);
    userMemory.setBytes(userMemory.getBytes() - 300_000_000);
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 300_000_000, 0, 200_000_000);
    userMemory.setBytes(userMemory.getBytes() - 300_000_000);
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 0, 0, 200_000_000);
    operatorContext.destroy();
    assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 0, 0, 0);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Test(org.testng.annotations.Test)

Example 23 with LocalMemoryContext

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

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

Example 24 with LocalMemoryContext

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

the class TestMemoryTracking method testLocalTotalMemoryLimitExceeded.

@Test
public void testLocalTotalMemoryLimitExceeded() {
    LocalMemoryContext systemMemoryContext = operatorContext.newLocalSystemMemoryContext("test");
    systemMemoryContext.setBytes(100);
    assertOperatorMemoryAllocations(operatorContext.getOperatorMemoryContext(), 0, 100, 0);
    systemMemoryContext.setBytes(queryMaxTotalMemory.toBytes());
    assertOperatorMemoryAllocations(operatorContext.getOperatorMemoryContext(), 0, queryMaxTotalMemory.toBytes(), 0);
    try {
        systemMemoryContext.setBytes(queryMaxTotalMemory.toBytes() + 1);
        fail("allocation should hit the per-node total memory limit");
    } catch (ExceededMemoryLimitException e) {
        assertEquals(e.getMessage(), format("Query exceeded per-node total memory limit of %1$s [Allocated: %1$s, Delta: 1B, Top Consumers: {test=%1$s}]", queryMaxTotalMemory));
    }
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) ExceededMemoryLimitException(com.facebook.presto.ExceededMemoryLimitException) Test(org.testng.annotations.Test)

Example 25 with LocalMemoryContext

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

the class TestMemoryTracking method testCumulativeTotalMemoryEstimation.

@Test
public void testCumulativeTotalMemoryEstimation() {
    LocalMemoryContext userMemory = operatorContext.localUserMemoryContext();
    LocalMemoryContext systemMemory = operatorContext.localSystemMemoryContext();
    long userMemoryBytes = 100_000_000;
    long systemMemoryBytes = 40_000_000;
    userMemory.setBytes(userMemoryBytes);
    systemMemory.setBytes(systemMemoryBytes);
    long startTime = System.nanoTime();
    double cumulativeTotalMemory = taskContext.getTaskStats().getCumulativeTotalMemory();
    long endTime = System.nanoTime();
    double elapsedTimeInMillis = (endTime - startTime) / 1_000_000.0;
    long averageMemoryForLastPeriod = (userMemoryBytes + systemMemoryBytes) / 2;
    assertTrue(cumulativeTotalMemory < elapsedTimeInMillis * averageMemoryForLastPeriod);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) 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