Search in sources :

Example 1 with MemoryPoolId

use of io.prestosql.spi.memory.MemoryPoolId in project hetu-core by openlookeng.

the class TestMemoryTracking method setUpTest.

@BeforeMethod
public void setUpTest() {
    memoryPool = new MemoryPool(new MemoryPoolId("test"), memoryPoolSize);
    queryContext = new QueryContext(new QueryId("test_query"), queryMaxMemory, queryMaxTotalMemory, memoryPool, new TestingGcMonitor(), notificationExecutor, yieldExecutor, queryMaxSpillSize, spillSpaceTracker, NOOP_SNAPSHOT_UTILS);
    taskContext = queryContext.addTaskContext(new TaskStateMachine(new TaskId("query", 0, 0), notificationExecutor), testSessionBuilder().build(), true, true, OptionalInt.empty(), Optional.empty(), TESTING_SERDE_FACTORY);
    pipelineContext = taskContext.addPipelineContext(0, true, true, false);
    driverContext = pipelineContext.addDriverContext();
    operatorContext = driverContext.addOperatorContext(1, new PlanNodeId("a"), "test-operator");
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TaskId(io.prestosql.execution.TaskId) QueryId(io.prestosql.spi.QueryId) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) MemoryPoolId(io.prestosql.spi.memory.MemoryPoolId) TaskStateMachine(io.prestosql.execution.TaskStateMachine) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with MemoryPoolId

use of io.prestosql.spi.memory.MemoryPoolId in project hetu-core by openlookeng.

the class TestBasicQueryInfo method testConstructor.

@Test
public void testConstructor() {
    BasicQueryInfo basicInfo = new BasicQueryInfo(new QueryInfo(new QueryId("0"), TEST_SESSION.toSessionRepresentation(), RUNNING, new MemoryPoolId("reserved"), false, URI.create("1"), ImmutableList.of("2", "3"), "SELECT 4", Optional.empty(), new QueryStats(DateTime.parse("1991-09-06T05:00-05:30"), DateTime.parse("1991-09-06T05:01-05:30"), DateTime.parse("1991-09-06T05:02-05:30"), DateTime.parse("1991-09-06T06:00-05:30"), Duration.valueOf("8m"), Duration.valueOf("7m"), Duration.valueOf("34m"), Duration.valueOf("35m"), Duration.valueOf("44m"), Duration.valueOf("9m"), Duration.valueOf("10m"), Duration.valueOf("11m"), Duration.valueOf("12m"), Duration.valueOf("12m"), Duration.valueOf("12m"), 13, 14, 15, 16, 17, 18, 34, 19, 20.0, DataSize.valueOf("21GB"), DataSize.valueOf("22GB"), DataSize.valueOf("23GB"), DataSize.valueOf("24GB"), DataSize.valueOf("25GB"), DataSize.valueOf("26GB"), DataSize.valueOf("27GB"), DataSize.valueOf("28GB"), DataSize.valueOf("29GB"), true, Duration.valueOf("23m"), Duration.valueOf("24m"), Duration.valueOf("26m"), true, ImmutableSet.of(BlockedReason.WAITING_FOR_MEMORY), DataSize.valueOf("271GB"), 281, DataSize.valueOf("272GB"), 282, DataSize.valueOf("27GB"), 28, DataSize.valueOf("29GB"), 30, DataSize.valueOf("31GB"), 32, DataSize.valueOf("32GB"), ImmutableList.of(new StageGcStatistics(101, 102, 103, 104, 105, 106, 107)), ImmutableList.of()), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), ImmutableSet.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty(), false, "33", Optional.empty(), null, StandardErrorCode.ABANDONED_QUERY.toErrorCode(), ImmutableList.of(), ImmutableSet.of(), Optional.empty(), false, Optional.empty(), false));
    assertEquals(basicInfo.getQueryId().getId(), "0");
    assertEquals(basicInfo.getState(), RUNNING);
    assertEquals(basicInfo.getMemoryPool().getId(), "reserved");
    assertEquals(basicInfo.isScheduled(), false);
    assertEquals(basicInfo.getQuery(), "SELECT 4");
    assertEquals(basicInfo.getQueryStats().getCreateTime(), DateTime.parse("1991-09-06T05:00-05:30"));
    assertEquals(basicInfo.getQueryStats().getEndTime(), DateTime.parse("1991-09-06T06:00-05:30"));
    assertEquals(basicInfo.getQueryStats().getElapsedTime(), Duration.valueOf("8m"));
    assertEquals(basicInfo.getQueryStats().getExecutionTime(), Duration.valueOf("44m"));
    assertEquals(basicInfo.getQueryStats().getTotalDrivers(), 16);
    assertEquals(basicInfo.getQueryStats().getQueuedDrivers(), 17);
    assertEquals(basicInfo.getQueryStats().getRunningDrivers(), 18);
    assertEquals(basicInfo.getQueryStats().getCompletedDrivers(), 19);
    assertEquals(basicInfo.getQueryStats().getCumulativeUserMemory(), 20.0);
    assertEquals(basicInfo.getQueryStats().getUserMemoryReservation(), DataSize.valueOf("21GB"));
    assertEquals(basicInfo.getQueryStats().getTotalMemoryReservation(), DataSize.valueOf("23GB"));
    assertEquals(basicInfo.getQueryStats().getPeakUserMemoryReservation(), DataSize.valueOf("24GB"));
    assertEquals(basicInfo.getQueryStats().getTotalCpuTime(), Duration.valueOf("24m"));
    assertEquals(basicInfo.getQueryStats().isFullyBlocked(), true);
    assertEquals(basicInfo.getQueryStats().getBlockedReasons(), ImmutableSet.of(BlockedReason.WAITING_FOR_MEMORY));
    assertEquals(basicInfo.getQueryStats().getProgressPercentage(), OptionalDouble.of(100));
    assertEquals(basicInfo.getErrorCode(), StandardErrorCode.ABANDONED_QUERY.toErrorCode());
    assertEquals(basicInfo.getErrorType(), StandardErrorCode.ABANDONED_QUERY.toErrorCode().getType());
}
Also used : QueryStats(io.prestosql.execution.QueryStats) QueryId(io.prestosql.spi.QueryId) QueryInfo(io.prestosql.execution.QueryInfo) StageGcStatistics(io.prestosql.spi.eventlistener.StageGcStatistics) MemoryPoolId(io.prestosql.spi.memory.MemoryPoolId) Test(org.testng.annotations.Test)

Example 3 with MemoryPoolId

use of io.prestosql.spi.memory.MemoryPoolId in project hetu-core by openlookeng.

the class MemoryLocalQueryRunner method execute.

public List<Page> execute(@Language("SQL") String query) {
    MemoryPool memoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(2, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(new DataSize(1, GIGABYTE));
    QueryContext queryContext = new QueryContext(new QueryId("test"), new DataSize(1, GIGABYTE), new DataSize(2, GIGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(4, GIGABYTE), spillSpaceTracker, NOOP_SNAPSHOT_UTILS);
    TaskContext taskContext = queryContext.addTaskContext(new TaskStateMachine(new TaskId("query", 0, 0), localQueryRunner.getExecutor()), localQueryRunner.getDefaultSession(), false, false, OptionalInt.empty(), Optional.empty(), TESTING_SERDE_FACTORY);
    // Use NullOutputFactory to avoid coping out results to avoid affecting benchmark results
    ImmutableList.Builder<Page> output = ImmutableList.builder();
    List<Driver> drivers = localQueryRunner.createDrivers(query, new PageConsumerOperator.PageConsumerOutputFactory(types -> output::add), taskContext);
    boolean done = false;
    while (!done) {
        boolean processed = false;
        for (Driver driver : drivers) {
            if (!driver.isFinished()) {
                driver.process();
                processed = true;
            }
        }
        done = !processed;
    }
    return output.build();
}
Also used : TESTING_SERDE_FACTORY(io.prestosql.testing.TestingPagesSerdeFactory.TESTING_SERDE_FACTORY) TaskId(io.prestosql.execution.TaskId) TaskStateMachine(io.prestosql.execution.TaskStateMachine) Plugin(io.prestosql.spi.Plugin) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) SpillSpaceTracker(io.prestosql.spiller.SpillSpaceTracker) TaskContext(io.prestosql.operator.TaskContext) TableHandle(io.prestosql.spi.metadata.TableHandle) OptionalInt(java.util.OptionalInt) MemoryPool(io.prestosql.memory.MemoryPool) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Session(io.prestosql.Session) QueryId(io.prestosql.spi.QueryId) PageConsumerOperator(io.prestosql.testing.PageConsumerOperator) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) NOOP_SNAPSHOT_UTILS(io.prestosql.testing.TestingSnapshotUtils.NOOP_SNAPSHOT_UTILS) Page(io.prestosql.spi.Page) QueryContext(io.prestosql.memory.QueryContext) MemoryConnectorFactory(io.prestosql.plugin.memory.MemoryConnectorFactory) MemoryPoolId(io.prestosql.spi.memory.MemoryPoolId) Metadata(io.prestosql.metadata.Metadata) DataSize(io.airlift.units.DataSize) LocalQueryRunner(io.prestosql.testing.LocalQueryRunner) List(java.util.List) Driver(io.prestosql.operator.Driver) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) SpillSpaceTracker(io.prestosql.spiller.SpillSpaceTracker) TaskContext(io.prestosql.operator.TaskContext) TaskId(io.prestosql.execution.TaskId) ImmutableList(com.google.common.collect.ImmutableList) QueryId(io.prestosql.spi.QueryId) Driver(io.prestosql.operator.Driver) Page(io.prestosql.spi.Page) QueryContext(io.prestosql.memory.QueryContext) TaskStateMachine(io.prestosql.execution.TaskStateMachine) PageConsumerOperator(io.prestosql.testing.PageConsumerOperator) DataSize(io.airlift.units.DataSize) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) MemoryPoolId(io.prestosql.spi.memory.MemoryPoolId) MemoryPool(io.prestosql.memory.MemoryPool)

Example 4 with MemoryPoolId

use of io.prestosql.spi.memory.MemoryPoolId in project hetu-core by openlookeng.

the class LowMemoryKillerTestingUtils method toNodeMemoryInfoList.

static List<MemoryInfo> toNodeMemoryInfoList(long maxReservedPoolBytes, long maxGeneralPoolBytes, String reservedQuery, Map<String, Map<String, Long>> queries) {
    Map<InternalNode, NodeReservation> nodeReservations = new HashMap<>();
    for (Map.Entry<String, Map<String, Long>> entry : queries.entrySet()) {
        QueryId queryId = new QueryId(entry.getKey());
        Map<String, Long> reservationByNode = entry.getValue();
        for (Map.Entry<String, Long> nodeEntry : reservationByNode.entrySet()) {
            InternalNode node = new InternalNode(nodeEntry.getKey(), URI.create("http://localhost"), new NodeVersion("version"), false);
            long bytes = nodeEntry.getValue();
            if (bytes == 0) {
                continue;
            }
            if (reservedQuery.equals(entry.getKey())) {
                nodeReservations.computeIfAbsent(node, ignored -> new NodeReservation()).getReserved().add(queryId, bytes);
            } else {
                nodeReservations.computeIfAbsent(node, ignored -> new NodeReservation()).getGeneral().add(queryId, bytes);
            }
        }
    }
    ImmutableList.Builder<MemoryInfo> result = ImmutableList.builder();
    for (Map.Entry<InternalNode, NodeReservation> entry : nodeReservations.entrySet()) {
        NodeReservation nodeReservation = entry.getValue();
        ImmutableMap.Builder<MemoryPoolId, MemoryPoolInfo> pools = ImmutableMap.builder();
        if (nodeReservation.getGeneral().getTotalReservedBytes() > 0) {
            pools.put(GENERAL_POOL, new MemoryPoolInfo(maxGeneralPoolBytes, nodeReservation.getGeneral().getTotalReservedBytes(), 0, nodeReservation.getGeneral().getReservationByQuery(), ImmutableMap.of(), ImmutableMap.of()));
        }
        if (nodeReservation.getReserved().getTotalReservedBytes() > 0) {
            pools.put(RESERVED_POOL, new MemoryPoolInfo(maxReservedPoolBytes, nodeReservation.getReserved().getTotalReservedBytes(), 0, nodeReservation.getReserved().getReservationByQuery(), ImmutableMap.of(), ImmutableMap.of()));
        }
        result.add(new MemoryInfo(7, 0.0, 0.0, new DataSize(maxReservedPoolBytes + maxGeneralPoolBytes, BYTE), pools.build()));
    }
    return result.build();
}
Also used : HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) QueryId(io.prestosql.spi.QueryId) ImmutableMap(com.google.common.collect.ImmutableMap) NodeVersion(io.prestosql.client.NodeVersion) DataSize(io.airlift.units.DataSize) MemoryPoolInfo(io.prestosql.spi.memory.MemoryPoolInfo) InternalNode(io.prestosql.metadata.InternalNode) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) MemoryPoolId(io.prestosql.spi.memory.MemoryPoolId)

Example 5 with MemoryPoolId

use of io.prestosql.spi.memory.MemoryPoolId in project hetu-core by openlookeng.

the class TestMemoryPools method testTaggedAllocations.

@Test
public void testTaggedAllocations() {
    QueryId testQuery = new QueryId("test_query");
    MemoryPool testPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(1000, BYTE));
    testPool.reserve(testQuery, "test_tag", 10);
    Map<String, Long> allocations = testPool.getTaggedMemoryAllocations().get(testQuery);
    assertEquals(allocations, ImmutableMap.of("test_tag", 10L));
    // free 5 bytes for test_tag
    testPool.free(testQuery, "test_tag", 5);
    assertEquals(allocations, ImmutableMap.of("test_tag", 5L));
    testPool.reserve(testQuery, "test_tag2", 20);
    assertEquals(allocations, ImmutableMap.of("test_tag", 5L, "test_tag2", 20L));
    // free the remaining 5 bytes for test_tag
    testPool.free(testQuery, "test_tag", 5);
    assertEquals(allocations, ImmutableMap.of("test_tag2", 20L));
    // free all for test_tag2
    testPool.free(testQuery, "test_tag2", 20);
    assertEquals(testPool.getTaggedMemoryAllocations().size(), 0);
}
Also used : QueryId(io.prestosql.spi.QueryId) DataSize(io.airlift.units.DataSize) AtomicLong(java.util.concurrent.atomic.AtomicLong) MemoryPoolId(io.prestosql.spi.memory.MemoryPoolId) Test(org.testng.annotations.Test)

Aggregations

MemoryPoolId (io.prestosql.spi.memory.MemoryPoolId)17 DataSize (io.airlift.units.DataSize)14 QueryId (io.prestosql.spi.QueryId)12 TestingGcMonitor (io.airlift.stats.TestingGcMonitor)7 MemoryPool (io.prestosql.memory.MemoryPool)6 SpillSpaceTracker (io.prestosql.spiller.SpillSpaceTracker)6 QueryContext (io.prestosql.memory.QueryContext)5 Test (org.testng.annotations.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 TaskId (io.prestosql.execution.TaskId)4 TaskStateMachine (io.prestosql.execution.TaskStateMachine)4 Session (io.prestosql.Session)3 TaskContext (io.prestosql.operator.TaskContext)3 HashMap (java.util.HashMap)3 ImmutableList (com.google.common.collect.ImmutableList)2 TpchConnectorFactory (io.prestosql.plugin.tpch.TpchConnectorFactory)2 Page (io.prestosql.spi.Page)2 MemoryPoolInfo (io.prestosql.spi.memory.MemoryPoolInfo)2 Map (java.util.Map)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2