Search in sources :

Example 11 with MemoryPool

use of com.facebook.presto.memory.MemoryPool in project presto by prestodb.

the class TestMemoryRevokingScheduler method testQueryMemoryNotRevokedWhenNotEnabled.

@Test
public void testQueryMemoryNotRevokedWhenNotEnabled() throws Exception {
    // The various tasks created here use a small amount of system memory independent of what's set explicitly
    // in this test. Triggering spilling based on differences of thousands of bytes rather than hundreds
    // makes the test resilient to any noise that creates.
    QueryId queryId = new QueryId("query");
    // use a larger memory pool so that we don't trigger spilling due to filling the memory pool
    MemoryPool queryLimitMemoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(100, GIGABYTE));
    SqlTask sqlTask1 = newSqlTask(queryId, queryLimitMemoryPool);
    TestOperatorContext operatorContext11 = createTestingOperatorContexts(sqlTask1, "operator11");
    allOperatorContexts = ImmutableSet.of(operatorContext11);
    List<SqlTask> tasks = ImmutableList.of(sqlTask1);
    MemoryRevokingScheduler scheduler = new MemoryRevokingScheduler(singletonList(queryLimitMemoryPool), () -> tasks, queryContexts::get, 1.0, 1.0, ORDER_BY_REVOCABLE_BYTES, false);
    try {
        scheduler.start();
        assertMemoryRevokingNotRequested();
        // exceed the query memory limit of 500KB
        operatorContext11.localRevocableMemoryContext().setBytes(600_000);
        scheduler.awaitAsynchronousCallbacksRun();
        assertMemoryRevokingNotRequested();
    } finally {
        scheduler.stop();
    }
}
Also used : SqlTask.createSqlTask(com.facebook.presto.execution.SqlTask.createSqlTask) QueryId(com.facebook.presto.spi.QueryId) DataSize(io.airlift.units.DataSize) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) MemoryPool(com.facebook.presto.memory.MemoryPool) Test(org.testng.annotations.Test)

Example 12 with MemoryPool

use of com.facebook.presto.memory.MemoryPool in project presto by prestodb.

the class TestMemoryRevokingScheduler method testCountAlreadyRevokedMemoryWithinAPool.

@Test
public void testCountAlreadyRevokedMemoryWithinAPool() throws Exception {
    // Given
    MemoryPool anotherMemoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(10, BYTE));
    SqlTask sqlTask1 = newSqlTask(new QueryId("q1"), anotherMemoryPool);
    OperatorContext operatorContext1 = createContexts(sqlTask1);
    SqlTask sqlTask2 = newSqlTask(new QueryId("q2"), memoryPool);
    OperatorContext operatorContext2 = createContexts(sqlTask2);
    List<SqlTask> tasks = ImmutableList.of(sqlTask1, sqlTask2);
    MemoryRevokingScheduler scheduler = new MemoryRevokingScheduler(asList(memoryPool, anotherMemoryPool), () -> tasks, queryContexts::get, 1.0, 1.0, ORDER_BY_CREATE_TIME, false);
    try {
        scheduler.start();
        allOperatorContexts = ImmutableSet.of(operatorContext1, operatorContext2);
        /*
             * sqlTask1 fills its pool
             */
        operatorContext1.localRevocableMemoryContext().setBytes(12);
        scheduler.awaitAsynchronousCallbacksRun();
        assertMemoryRevokingRequestedFor(operatorContext1);
        /*
             * When sqlTask2 fills its pool
             */
        operatorContext2.localRevocableMemoryContext().setBytes(12);
        scheduler.awaitAsynchronousCallbacksRun();
        /*
             * Then sqlTask2 should be asked to revoke its memory too
             */
        assertMemoryRevokingRequestedFor(operatorContext1, operatorContext2);
    } finally {
        scheduler.stop();
    }
}
Also used : SqlTask.createSqlTask(com.facebook.presto.execution.SqlTask.createSqlTask) DataSize(io.airlift.units.DataSize) QueryId(com.facebook.presto.spi.QueryId) OperatorContext(com.facebook.presto.operator.OperatorContext) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) MemoryPool(com.facebook.presto.memory.MemoryPool) Test(org.testng.annotations.Test)

Aggregations

MemoryPool (com.facebook.presto.memory.MemoryPool)12 DataSize (io.airlift.units.DataSize)10 QueryId (com.facebook.presto.spi.QueryId)9 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)9 QueryContext (com.facebook.presto.memory.QueryContext)6 TestingGcMonitor (com.facebook.airlift.stats.TestingGcMonitor)5 SpillSpaceTracker (com.facebook.presto.spiller.SpillSpaceTracker)5 TaskContext (com.facebook.presto.operator.TaskContext)4 Session (com.facebook.presto.Session)3 SqlTask.createSqlTask (com.facebook.presto.execution.SqlTask.createSqlTask)3 TaskId (com.facebook.presto.execution.TaskId)3 TaskStateMachine (com.facebook.presto.execution.TaskStateMachine)3 OperatorContext (com.facebook.presto.operator.OperatorContext)3 Page (com.facebook.presto.common.Page)2 TaskMemoryReservationSummary (com.facebook.presto.operator.TaskMemoryReservationSummary)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 List (java.util.List)2 Test (org.testng.annotations.Test)2 JsonCodec.listJsonCodec (com.facebook.airlift.json.JsonCodec.listJsonCodec)1