Search in sources :

Example 26 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestQueues method testRunningQuery.

@Test(timeOut = 60_000)
public void testRunningQuery() throws Exception {
    try (DistributedQueryRunner queryRunner = getSimpleQueryRunner()) {
        queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
        while (true) {
            TimeUnit.SECONDS.sleep(2);
            ResourceGroupInfo global = queryRunner.getCoordinator().getResourceGroupManager().get().getResourceGroupInfo(new ResourceGroupId(new ResourceGroupId("global"), "bi-user"));
            if (global.getSoftMemoryLimit().toBytes() > 0) {
                break;
            }
        }
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupInfo(com.facebook.presto.spi.resourceGroups.ResourceGroupInfo) Test(org.testng.annotations.Test)

Example 27 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class InternalResourceGroupManager method submit.

@Override
public void submit(Statement statement, QueryExecution queryExecution, Executor executor) {
    checkState(configurationManager.get() != null, "configurationManager not set");
    ResourceGroupId group;
    try {
        group = selectGroup(queryExecution.getSession());
    } catch (PrestoException e) {
        queryExecution.fail(e);
        return;
    }
    createGroupIfNecessary(group, queryExecution.getSession(), executor);
    groups.get(group).run(queryExecution);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) PrestoException(com.facebook.presto.spi.PrestoException)

Example 28 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestResourceManagerClusterStateProvider method assertResourceGroup.

private void assertResourceGroup(ResourceManagerClusterStateProvider provider, String excludingNode, String resourceGroupId, int queuedQueries, int runningQueries, DataSize userMemoryReservation) throws ResourceManagerInconsistentException {
    ResourceGroupId currResourceGroupId = new ResourceGroupId(Arrays.asList(resourceGroupId.split("\\.")));
    List<ResourceGroupRuntimeInfo> list = provider.getClusterResourceGroups(excludingNode);
    Optional<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfo = list.stream().filter(resourceGroupInfo -> currResourceGroupId.equals(resourceGroupInfo.getResourceGroupId())).findFirst();
    assertTrue(resourceGroupRuntimeInfo.isPresent(), "Resource group " + resourceGroupId + " not found");
    ResourceGroupRuntimeInfo info = resourceGroupRuntimeInfo.get();
    ResourceGroupId rg = new ResourceGroupId(Arrays.asList(resourceGroupId.split("\\.")));
    assertEquals(info.getQueuedQueries(), queuedQueries, format("Expected %s queued queries, found %s", queuedQueries, info.getQueuedQueries()));
    assertEquals(info.getRunningQueries(), runningQueries, format("Expected %s running queries, found %s", runningQueries, info.getRunningQueries()));
    assertEquals(info.getResourceGroupId(), rg, format("Expected resource group id %s, found %s", resourceGroupId, info.getResourceGroupId()));
    assertEquals(info.getMemoryUsageBytes(), userMemoryReservation.toBytes(), format("Expected %s user memory reservation found %s", userMemoryReservation, DataSize.succinctBytes(info.getMemoryUsageBytes())));
}
Also used : Arrays(java.util.Arrays) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) Duration(io.airlift.units.Duration) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) WAITING_FOR_MEMORY(com.facebook.presto.operator.BlockedReason.WAITING_FOR_MEMORY) Map(java.util.Map) FAILED(com.facebook.presto.execution.QueryState.FAILED) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Assert.assertNotNull(org.testng.Assert.assertNotNull) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) String.format(java.lang.String.format) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) OptionalDouble(java.util.OptionalDouble) Assert.assertEquals(org.testng.Assert.assertEquals) MemoryInfo(com.facebook.presto.memory.MemoryInfo) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) DateTime(org.joda.time.DateTime) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Assert.assertTrue(org.testng.Assert.assertTrue) STARTING(com.facebook.presto.execution.QueryState.STARTING) QueryState(com.facebook.presto.execution.QueryState) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Example 29 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestResourceManagerClusterStateProvider method assertNonLeafResourceGroup.

private void assertNonLeafResourceGroup(ResourceManagerClusterStateProvider provider, String excludingNode, String resourceGroupId, int queuedQueries, int runningQueries, int descendantQueuedQueries, int descendantRunningQueries) throws ResourceManagerInconsistentException {
    List<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfos = provider.getClusterResourceGroups(excludingNode);
    Optional<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfo = provider.getClusterResourceGroups(excludingNode).stream().filter(resourceGroupInfo -> new ResourceGroupId(resourceGroupId).equals(resourceGroupInfo.getResourceGroupId())).findFirst();
    assertTrue(resourceGroupRuntimeInfo.isPresent(), "Resource group " + resourceGroupId + " not found");
    ResourceGroupRuntimeInfo info = resourceGroupRuntimeInfo.get();
    assertEquals(info.getQueuedQueries(), queuedQueries, format("Expected %s queued queries, found %s", queuedQueries, info.getQueuedQueries()));
    assertEquals(info.getRunningQueries(), runningQueries, format("Expected %s running queries, found %s", runningQueries, info.getRunningQueries()));
    assertEquals(info.getDescendantQueuedQueries(), descendantQueuedQueries, format("Expected %s descendant queued queries, found %s", descendantQueuedQueries, info.getDescendantQueuedQueries()));
    assertEquals(info.getDescendantRunningQueries(), descendantRunningQueries, format("Expected %s descendant running queries, found %s", descendantRunningQueries, info.getDescendantRunningQueries()));
    assertEquals(info.getResourceGroupId(), new ResourceGroupId(resourceGroupId), format("Expected resource group id %s, found %s", resourceGroupId, info.getResourceGroupId()));
}
Also used : Arrays(java.util.Arrays) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) Duration(io.airlift.units.Duration) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) WAITING_FOR_MEMORY(com.facebook.presto.operator.BlockedReason.WAITING_FOR_MEMORY) Map(java.util.Map) FAILED(com.facebook.presto.execution.QueryState.FAILED) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Assert.assertNotNull(org.testng.Assert.assertNotNull) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) String.format(java.lang.String.format) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) OptionalDouble(java.util.OptionalDouble) Assert.assertEquals(org.testng.Assert.assertEquals) MemoryInfo(com.facebook.presto.memory.MemoryInfo) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) DateTime(org.joda.time.DateTime) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Assert.assertTrue(org.testng.Assert.assertTrue) STARTING(com.facebook.presto.execution.QueryState.STARTING) QueryState(com.facebook.presto.execution.QueryState) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Example 30 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestResourceManagerResourceGroupService method testGetResourceGroupInfo.

@Test
public void testGetResourceGroupInfo() throws Exception {
    TestingResourceManagerClient resourceManagerClient = new TestingResourceManagerClient();
    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    ResourceManagerConfig resourceManagerConfig = new ResourceManagerConfig();
    ResourceManagerResourceGroupService service = new ResourceManagerResourceGroupService((addressSelectionContext, headers) -> resourceManagerClient, resourceManagerConfig, nodeManager);
    List<ResourceGroupRuntimeInfo> resourceGroupInfos = service.getResourceGroupInfo();
    assertNotNull(resourceGroupInfos);
    assertTrue(resourceGroupInfos.isEmpty());
    assertEquals(resourceManagerClient.getResourceGroupInfoCalls("local"), 1);
    resourceManagerClient.setResourceGroupRuntimeInfos(ImmutableList.of(new ResourceGroupRuntimeInfo(new ResourceGroupId("global"), 1, 2, 3, 0, 1)));
    Thread.sleep(SECONDS.toMillis(2));
    resourceGroupInfos = service.getResourceGroupInfo();
    assertNotNull(resourceGroupInfos);
    assertEquals(resourceGroupInfos.size(), 1);
    assertEquals(resourceManagerClient.getResourceGroupInfoCalls("local"), 2);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) Test(org.testng.annotations.Test)

Aggregations

ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)41 Test (org.testng.annotations.Test)31 QueryId (com.facebook.presto.spi.QueryId)12 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)9 ResourceGroupInfo (com.facebook.presto.server.ResourceGroupInfo)5 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Duration (io.airlift.units.Duration)5 String.format (java.lang.String.format)5 Optional (java.util.Optional)5 TestQueues.createResourceGroupId (com.facebook.presto.execution.TestQueues.createResourceGroupId)4 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)3 DataSize (io.airlift.units.DataSize)3 HashMap (java.util.HashMap)3 SECONDS (java.util.concurrent.TimeUnit.SECONDS)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Assert.assertTrue (org.testng.Assert.assertTrue)3 Session (com.facebook.presto.Session)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2