Search in sources :

Example 1 with QueryStateInfo

use of io.trino.server.QueryStateInfo in project trino by trinodb.

the class TestResourceGroups method testGetResourceGroupStateInfo.

@Test
public void testGetResourceGroupStateInfo() {
    InternalResourceGroup root = new InternalResourceGroup("root", (group, export) -> {
    }, directExecutor());
    root.setSoftMemoryLimitBytes(DataSize.of(1, GIGABYTE).toBytes());
    root.setMaxQueuedQueries(40);
    root.setHardConcurrencyLimit(10);
    root.setSchedulingPolicy(WEIGHTED);
    InternalResourceGroup rootA = root.getOrCreateSubGroup("a");
    rootA.setSoftMemoryLimitBytes(DataSize.of(10, MEGABYTE).toBytes());
    rootA.setMaxQueuedQueries(20);
    rootA.setHardConcurrencyLimit(0);
    InternalResourceGroup rootB = root.getOrCreateSubGroup("b");
    rootB.setSoftMemoryLimitBytes(DataSize.of(5, MEGABYTE).toBytes());
    rootB.setMaxQueuedQueries(20);
    rootB.setHardConcurrencyLimit(1);
    rootB.setSchedulingWeight(2);
    rootB.setSchedulingPolicy(QUERY_PRIORITY);
    InternalResourceGroup rootAX = rootA.getOrCreateSubGroup("x");
    rootAX.setSoftMemoryLimitBytes(DataSize.of(1, MEGABYTE).toBytes());
    rootAX.setMaxQueuedQueries(10);
    rootAX.setHardConcurrencyLimit(10);
    InternalResourceGroup rootAY = rootA.getOrCreateSubGroup("y");
    rootAY.setSoftMemoryLimitBytes(DataSize.of(1, MEGABYTE).toBytes());
    rootAY.setMaxQueuedQueries(10);
    rootAY.setHardConcurrencyLimit(10);
    Set<MockManagedQueryExecution> queries = fillGroupTo(rootAX, ImmutableSet.of(), 5, false);
    queries.addAll(fillGroupTo(rootAY, ImmutableSet.of(), 5, false));
    queries.addAll(fillGroupTo(rootB, ImmutableSet.of(), 10, true));
    ResourceGroupInfo rootInfo = root.getFullInfo();
    assertEquals(rootInfo.getId(), root.getId());
    assertEquals(rootInfo.getState(), CAN_RUN);
    assertEquals(rootInfo.getSoftMemoryLimit().toBytes(), root.getSoftMemoryLimitBytes());
    assertEquals(rootInfo.getMemoryUsage(), DataSize.ofBytes(0));
    assertEquals(rootInfo.getCpuUsage().toMillis(), 0);
    List<ResourceGroupInfo> subGroups = rootInfo.getSubGroups().get();
    assertEquals(subGroups.size(), 2);
    assertGroupInfoEquals(subGroups.get(0), rootA.getInfo());
    assertEquals(subGroups.get(0).getId(), rootA.getId());
    assertEquals(subGroups.get(0).getState(), CAN_QUEUE);
    assertEquals(subGroups.get(0).getSoftMemoryLimit().toBytes(), rootA.getSoftMemoryLimitBytes());
    assertEquals(subGroups.get(0).getHardConcurrencyLimit(), rootA.getHardConcurrencyLimit());
    assertEquals(subGroups.get(0).getMaxQueuedQueries(), rootA.getMaxQueuedQueries());
    assertEquals(subGroups.get(0).getNumEligibleSubGroups(), 2);
    assertEquals(subGroups.get(0).getNumRunningQueries(), 0);
    assertEquals(subGroups.get(0).getNumQueuedQueries(), 10);
    assertGroupInfoEquals(subGroups.get(1), rootB.getInfo());
    assertEquals(subGroups.get(1).getId(), rootB.getId());
    assertEquals(subGroups.get(1).getState(), CAN_QUEUE);
    assertEquals(subGroups.get(1).getSoftMemoryLimit().toBytes(), rootB.getSoftMemoryLimitBytes());
    assertEquals(subGroups.get(1).getHardConcurrencyLimit(), rootB.getHardConcurrencyLimit());
    assertEquals(subGroups.get(1).getMaxQueuedQueries(), rootB.getMaxQueuedQueries());
    assertEquals(subGroups.get(1).getNumEligibleSubGroups(), 0);
    assertEquals(subGroups.get(1).getNumRunningQueries(), 1);
    assertEquals(subGroups.get(1).getNumQueuedQueries(), 9);
    assertEquals(rootInfo.getSoftConcurrencyLimit(), root.getSoftConcurrencyLimit());
    assertEquals(rootInfo.getHardConcurrencyLimit(), root.getHardConcurrencyLimit());
    assertEquals(rootInfo.getMaxQueuedQueries(), root.getMaxQueuedQueries());
    assertEquals(rootInfo.getNumQueuedQueries(), 19);
    List<QueryStateInfo> runningQueries = rootInfo.getRunningQueries().get();
    assertEquals(runningQueries.size(), 1);
    QueryStateInfo queryInfo = runningQueries.get(0);
    assertEquals(queryInfo.getResourceGroupId(), Optional.of(rootB.getId()));
}
Also used : MockManagedQueryExecution(io.trino.execution.MockManagedQueryExecution) QueryStateInfo(io.trino.server.QueryStateInfo) ResourceGroupInfo(io.trino.server.ResourceGroupInfo) Test(org.testng.annotations.Test)

Aggregations

MockManagedQueryExecution (io.trino.execution.MockManagedQueryExecution)1 QueryStateInfo (io.trino.server.QueryStateInfo)1 ResourceGroupInfo (io.trino.server.ResourceGroupInfo)1 Test (org.testng.annotations.Test)1