Search in sources :

Example 6 with ResourceGroupRuntimeInfo

use of com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo 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 7 with ResourceGroupRuntimeInfo

use of com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo 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)

Example 8 with ResourceGroupRuntimeInfo

use of com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo in project presto by prestodb.

the class TestDistributedClusterStatsResource method getGlobalQueryCountIfAvailable.

private Optional<Integer> getGlobalQueryCountIfAvailable(QueryState state, TestingPrestoServer coordinator) {
    Map<ResourceGroupId, ResourceGroupRuntimeInfo> resourceGroupRuntimeInfoSnapshot = coordinator.getResourceGroupManager().get().getResourceGroupRuntimeInfosSnapshot();
    ResourceGroupRuntimeInfo resourceGroupRuntimeInfo = resourceGroupRuntimeInfoSnapshot.get(new ResourceGroupId(RESOURCE_GROUP_GLOBAL));
    if (resourceGroupRuntimeInfo == null) {
        return Optional.empty();
    }
    int queryCount = 0;
    switch(state) {
        case RUNNING:
            queryCount = resourceGroupRuntimeInfo.getDescendantRunningQueries();
            break;
        case QUEUED:
            queryCount = resourceGroupRuntimeInfo.getDescendantQueuedQueries();
            break;
        default:
            fail(format("Unexpected query state %s", state));
    }
    return Optional.of(queryCount);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Example 9 with ResourceGroupRuntimeInfo

use of com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo in project presto by prestodb.

the class TestDistributedQueuesDb method testDistributedQueue_burstTraffic.

@Test(timeOut = 2_000)
public void testDistributedQueue_burstTraffic() throws Exception {
    QueryId firstAdhocQuery = createQuery(queryRunner, 1, testSession(new Identity("user1", Optional.empty())), LONG_LASTING_QUERY);
    QueryId secondAdhocQuery = createQuery(queryRunner, 0, testSession(new Identity("user2", Optional.empty())), LONG_LASTING_QUERY);
    QueryId thirdAdhocQuery = createQuery(queryRunner, 1, testSession(new Identity("user3", Optional.empty())), LONG_LASTING_QUERY);
    QueryId fourthAdhocQuery = createQuery(queryRunner, 0, testSession(new Identity("user4", Optional.empty())), LONG_LASTING_QUERY);
    Map<ResourceGroupId, ResourceGroupRuntimeInfo> resourceGroupRuntimeInfoSnapshot;
    int globalRunningQueries = 0;
    int globalQueriedQueries = 0;
    do {
        MILLISECONDS.sleep(100);
        globalRunningQueries = 0;
        globalQueriedQueries = 0;
        for (int coordinator = 0; coordinator < 2; coordinator++) {
            resourceGroupRuntimeInfoSnapshot = queryRunner.getCoordinator(coordinator).getResourceGroupManager().get().getResourceGroupRuntimeInfosSnapshot();
            ResourceGroupRuntimeInfo resourceGroupRuntimeInfo = resourceGroupRuntimeInfoSnapshot.get(new ResourceGroupId("global"));
            if (resourceGroupRuntimeInfo != null) {
                globalRunningQueries += resourceGroupRuntimeInfo.getDescendantRunningQueries();
                globalQueriedQueries += resourceGroupRuntimeInfo.getDescendantQueuedQueries();
            }
        }
    } while (globalRunningQueries != 3 && globalQueriedQueries != 1);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) QueryId(com.facebook.presto.spi.QueryId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) Identity(com.facebook.presto.spi.security.Identity) Test(org.testng.annotations.Test)

Aggregations

ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)9 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)9 QueryId (com.facebook.presto.spi.QueryId)7 Test (org.testng.annotations.Test)7 QUEUED (com.facebook.presto.execution.QueryState.QUEUED)3 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)3 RESERVED_POOL (com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL)3 MemoryInfo (com.facebook.presto.memory.MemoryInfo)3 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)3 InternalNode (com.facebook.presto.metadata.InternalNode)3 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)3 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)3 NodeStatus (com.facebook.presto.server.NodeStatus)3 ClusterMemoryPoolInfo (com.facebook.presto.spi.memory.ClusterMemoryPoolInfo)3 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Duration (io.airlift.units.Duration)3 String.format (java.lang.String.format)3 URI (java.net.URI)3