Search in sources :

Example 6 with ClusterMemoryPoolInfo

use of com.facebook.presto.spi.memory.ClusterMemoryPoolInfo in project urban-eureka by errir503.

the class TestResourceManagerClusterStateProvider method assertMemoryPoolMap.

private void assertMemoryPoolMap(ResourceManagerClusterStateProvider provider, int memoryPoolSize, MemoryPoolId memoryPoolId, int assignedQueries, int blockedNodes, int maxBytes, int reservedBytes, int reservedRevocableBytes, Optional<String> largestMemoryQuery) {
    Map<MemoryPoolId, ClusterMemoryPoolInfo> memoryPoolMap = provider.getClusterMemoryPoolInfo();
    assertNotNull(memoryPoolMap);
    assertEquals(memoryPoolMap.size(), memoryPoolSize);
    ClusterMemoryPoolInfo clusterMemoryPoolInfo = memoryPoolMap.get(memoryPoolId);
    assertNotNull(clusterMemoryPoolInfo);
    assertEquals(clusterMemoryPoolInfo.getAssignedQueries(), assignedQueries);
    assertEquals(clusterMemoryPoolInfo.getBlockedNodes(), blockedNodes);
    assertEquals(clusterMemoryPoolInfo.getMemoryPoolInfo().getMaxBytes(), maxBytes);
    assertEquals(clusterMemoryPoolInfo.getMemoryPoolInfo().getReservedBytes(), reservedBytes);
    assertEquals(clusterMemoryPoolInfo.getMemoryPoolInfo().getReservedRevocableBytes(), reservedRevocableBytes);
    assertEquals(clusterMemoryPoolInfo.getLargestMemoryQuery().map(QueryId::getId), largestMemoryQuery);
}
Also used : ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId)

Example 7 with ClusterMemoryPoolInfo

use of com.facebook.presto.spi.memory.ClusterMemoryPoolInfo in project presto by prestodb.

the class ResourceManagerClusterStateProvider method getClusterMemoryPoolInfoInternal.

private Map<MemoryPoolId, ClusterMemoryPoolInfo> getClusterMemoryPoolInfoInternal() {
    List<MemoryInfo> memoryInfos = nodeStatuses.values().stream().map(nodeStatus -> nodeStatus.getNodeStatus().getMemoryInfo()).collect(toImmutableList());
    int queriesAssignedToGeneralPool = 0;
    int queriesAssignedToReservedPool = 0;
    Query largestGeneralPoolQuery = null;
    for (CoordinatorQueriesState nodeQueryState : nodeQueryStates.values()) {
        for (Query query : nodeQueryState.getActiveQueries()) {
            MemoryPoolId memoryPool = query.getBasicQueryInfo().getMemoryPool();
            if (GENERAL_POOL.equals(memoryPool)) {
                queriesAssignedToGeneralPool = Math.incrementExact(queriesAssignedToGeneralPool);
                if (!resourceOvercommit(query.getBasicQueryInfo().getSession().toSession(sessionPropertyManager))) {
                    largestGeneralPoolQuery = getLargestMemoryQuery(Optional.ofNullable(largestGeneralPoolQuery), query);
                }
            } else if (RESERVED_POOL.equals(memoryPool)) {
                queriesAssignedToReservedPool = Math.incrementExact(queriesAssignedToReservedPool);
            } else {
                throw new IllegalArgumentException("Unrecognized memory pool: " + memoryPool);
            }
        }
    }
    ImmutableMap.Builder<MemoryPoolId, ClusterMemoryPoolInfo> memoryPoolInfos = ImmutableMap.builder();
    ClusterMemoryPool pool = new ClusterMemoryPool(GENERAL_POOL);
    pool.update(memoryInfos, queriesAssignedToGeneralPool);
    ClusterMemoryPoolInfo clusterInfo = pool.getClusterInfo(Optional.ofNullable(largestGeneralPoolQuery).map(Query::getQueryId));
    memoryPoolInfos.put(GENERAL_POOL, clusterInfo);
    if (isReservedPoolEnabled) {
        pool = new ClusterMemoryPool(RESERVED_POOL);
        pool.update(memoryInfos, queriesAssignedToReservedPool);
        memoryPoolInfos.put(RESERVED_POOL, pool.getClusterInfo());
    }
    return memoryPoolInfos.build();
}
Also used : MemoryInfo(com.facebook.presto.memory.MemoryInfo) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ClusterMemoryPool(com.facebook.presto.memory.ClusterMemoryPool) MemoryInfo(com.facebook.presto.memory.MemoryInfo) Duration(io.airlift.units.Duration) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) Suppliers(com.google.common.base.Suppliers) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Stream.concat(java.util.stream.Stream.concat) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) NodeMemoryConfig(com.facebook.presto.memory.NodeMemoryConfig) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GuardedBy(javax.annotation.concurrent.GuardedBy) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Optional(java.util.Optional) SystemSessionProperties.resourceOvercommit(com.facebook.presto.SystemSessionProperties.resourceOvercommit) ClusterMemoryPool(com.facebook.presto.memory.ClusterMemoryPool) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 8 with ClusterMemoryPoolInfo

use of com.facebook.presto.spi.memory.ClusterMemoryPoolInfo in project presto by prestodb.

the class ClusterMemoryManager method isClusterOutOfMemory.

private synchronized boolean isClusterOutOfMemory() {
    ClusterMemoryPoolInfo reservedPool = getClusterInfo(RESERVED_POOL);
    ClusterMemoryPoolInfo generalPool = getClusterInfo(GENERAL_POOL);
    if (reservedPool == null) {
        return generalPool.getBlockedNodes() > 0;
    }
    return reservedPool.getAssignedQueries() > 0 && generalPool.getBlockedNodes() > 0;
}
Also used : ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo)

Example 9 with ClusterMemoryPoolInfo

use of com.facebook.presto.spi.memory.ClusterMemoryPoolInfo in project presto by prestodb.

the class TestMemoryManager method testClusterPoolsMultiCoordinator.

@Test(timeOut = 60_000)
public void testClusterPoolsMultiCoordinator() throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("task.verbose-stats", "true").put("resource-manager.memory-pool-fetch-interval", "10ms").put("resource-manager.query-heartbeat-interval", "10ms").put("resource-manager.node-status-timeout", "5s").build();
    try (DistributedQueryRunner queryRunner = createQueryRunner(properties, ImmutableMap.of(), properties, 2)) {
        // Reserve all the memory
        QueryId fakeQueryId = new QueryId("fake");
        for (TestingPrestoServer server : queryRunner.getCoordinatorWorkers()) {
            for (MemoryPool pool : server.getLocalMemoryManager().getPools()) {
                assertTrue(pool.tryReserve(fakeQueryId, "test", pool.getMaxBytes()));
            }
        }
        List<Future<?>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            int coordinator = i;
            queryFutures.add(executor.submit(() -> queryRunner.execute(coordinator, "SELECT COUNT(*), clerk FROM orders GROUP BY clerk")));
        }
        ClusterMemoryManager memoryManager = queryRunner.getCoordinator(0).getClusterMemoryManager();
        ClusterMemoryPoolInfo reservedPool;
        while ((reservedPool = memoryManager.getClusterInfo(RESERVED_POOL)) == null) {
            MILLISECONDS.sleep(10);
        }
        ClusterMemoryPoolInfo generalPool = memoryManager.getClusterInfo(GENERAL_POOL);
        assertNotNull(generalPool);
        // Wait for the queries to start running and get assigned to the expected pools
        while (generalPool.getAssignedQueries() != 1 || reservedPool.getAssignedQueries() != 1 || generalPool.getBlockedNodes() != 3 || reservedPool.getBlockedNodes() != 3) {
            generalPool = memoryManager.getClusterInfo(GENERAL_POOL);
            reservedPool = memoryManager.getClusterInfo(RESERVED_POOL);
            MILLISECONDS.sleep(10);
        }
        // Make sure the queries are blocked
        List<BasicQueryInfo> currentQueryInfos;
        do {
            currentQueryInfos = queryRunner.getCoordinators().stream().map(TestingPrestoServer::getQueryManager).map(QueryManager::getQueries).flatMap(Collection::stream).collect(toImmutableList());
            MILLISECONDS.sleep(10);
        } while (currentQueryInfos.size() != 2);
        for (BasicQueryInfo info : currentQueryInfos) {
            assertFalse(info.getState().isDone());
        }
        // Check that the pool information propagated to the query objects
        assertNotEquals(currentQueryInfos.get(0).getMemoryPool(), currentQueryInfos.get(1).getMemoryPool());
        while (!currentQueryInfos.stream().allMatch(TestMemoryManager::isBlockedWaitingForMemory)) {
            MILLISECONDS.sleep(10);
            currentQueryInfos = queryRunner.getCoordinators().stream().map(TestingPrestoServer::getQueryManager).map(QueryManager::getQueries).flatMap(Collection::stream).collect(toImmutableList());
            for (BasicQueryInfo info : currentQueryInfos) {
                assertFalse(info.getState().isDone());
            }
        }
        // Release the memory in the reserved pool
        for (TestingPrestoServer server : queryRunner.getCoordinatorWorkers()) {
            Optional<MemoryPool> reserved = server.getLocalMemoryManager().getReservedPool();
            assertTrue(reserved.isPresent());
            // Free up the entire pool
            reserved.get().free(fakeQueryId, "test", reserved.get().getMaxBytes());
            assertTrue(reserved.get().getFreeBytes() > 0);
        }
        // This also checks that the query in the general pool is successfully moved to the reserved pool.
        for (Future<?> query : queryFutures) {
            query.get();
        }
        queryRunner.getCoordinators().stream().map(TestingPrestoServer::getQueryManager).map(QueryManager::getQueries).flatMap(Collection::stream).forEach(info -> assertEquals(info.getState(), FINISHED));
        // Make sure we didn't leak any memory on the workers
        for (TestingPrestoServer worker : queryRunner.getCoordinatorWorkers()) {
            Optional<MemoryPool> reserved = worker.getLocalMemoryManager().getReservedPool();
            assertTrue(reserved.isPresent());
            assertEquals(reserved.get().getMaxBytes(), reserved.get().getFreeBytes());
            MemoryPool general = worker.getLocalMemoryManager().getGeneralPool();
            // Free up the memory we reserved earlier
            general.free(fakeQueryId, "test", general.getMaxBytes());
            assertEquals(general.getMaxBytes(), general.getFreeBytes());
        }
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) ArrayList(java.util.ArrayList) QueryManager(com.facebook.presto.execution.QueryManager) Future(java.util.concurrent.Future) Collection(java.util.Collection) Test(org.testng.annotations.Test)

Example 10 with ClusterMemoryPoolInfo

use of com.facebook.presto.spi.memory.ClusterMemoryPoolInfo in project urban-eureka by errir503.

the class ResourceManagerClusterStateProvider method getClusterMemoryPoolInfoInternal.

private Map<MemoryPoolId, ClusterMemoryPoolInfo> getClusterMemoryPoolInfoInternal() {
    List<MemoryInfo> memoryInfos = nodeStatuses.values().stream().map(nodeStatus -> nodeStatus.getNodeStatus().getMemoryInfo()).collect(toImmutableList());
    int queriesAssignedToGeneralPool = 0;
    int queriesAssignedToReservedPool = 0;
    Query largestGeneralPoolQuery = null;
    for (CoordinatorQueriesState nodeQueryState : nodeQueryStates.values()) {
        for (Query query : nodeQueryState.getActiveQueries()) {
            MemoryPoolId memoryPool = query.getBasicQueryInfo().getMemoryPool();
            if (GENERAL_POOL.equals(memoryPool)) {
                queriesAssignedToGeneralPool = Math.incrementExact(queriesAssignedToGeneralPool);
                if (!resourceOvercommit(query.getBasicQueryInfo().getSession().toSession(sessionPropertyManager))) {
                    largestGeneralPoolQuery = getLargestMemoryQuery(Optional.ofNullable(largestGeneralPoolQuery), query);
                }
            } else if (RESERVED_POOL.equals(memoryPool)) {
                queriesAssignedToReservedPool = Math.incrementExact(queriesAssignedToReservedPool);
            } else {
                throw new IllegalArgumentException("Unrecognized memory pool: " + memoryPool);
            }
        }
    }
    ImmutableMap.Builder<MemoryPoolId, ClusterMemoryPoolInfo> memoryPoolInfos = ImmutableMap.builder();
    ClusterMemoryPool pool = new ClusterMemoryPool(GENERAL_POOL);
    pool.update(memoryInfos, queriesAssignedToGeneralPool);
    ClusterMemoryPoolInfo clusterInfo = pool.getClusterInfo(Optional.ofNullable(largestGeneralPoolQuery).map(Query::getQueryId));
    memoryPoolInfos.put(GENERAL_POOL, clusterInfo);
    if (isReservedPoolEnabled) {
        pool = new ClusterMemoryPool(RESERVED_POOL);
        pool.update(memoryInfos, queriesAssignedToReservedPool);
        memoryPoolInfos.put(RESERVED_POOL, pool.getClusterInfo());
    }
    return memoryPoolInfos.build();
}
Also used : MemoryInfo(com.facebook.presto.memory.MemoryInfo) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ClusterMemoryPool(com.facebook.presto.memory.ClusterMemoryPool) MemoryInfo(com.facebook.presto.memory.MemoryInfo) Duration(io.airlift.units.Duration) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) Suppliers(com.google.common.base.Suppliers) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Stream.concat(java.util.stream.Stream.concat) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) NodeMemoryConfig(com.facebook.presto.memory.NodeMemoryConfig) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GuardedBy(javax.annotation.concurrent.GuardedBy) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Optional(java.util.Optional) SystemSessionProperties.resourceOvercommit(com.facebook.presto.SystemSessionProperties.resourceOvercommit) ClusterMemoryPool(com.facebook.presto.memory.ClusterMemoryPool) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Aggregations

ClusterMemoryPoolInfo (com.facebook.presto.spi.memory.ClusterMemoryPoolInfo)12 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)6 QueryId (com.facebook.presto.spi.QueryId)6 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)6 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)6 SystemSessionProperties.resourceOvercommit (com.facebook.presto.SystemSessionProperties.resourceOvercommit)4 QueryExecution (com.facebook.presto.execution.QueryExecution)4 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)4 RESERVED_POOL (com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL)4 InternalNode (com.facebook.presto.metadata.InternalNode)4 InternalNodeManager (com.facebook.presto.metadata.InternalNodeManager)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Duration (io.airlift.units.Duration)3 String.format (java.lang.String.format)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3