Search in sources :

Example 1 with GENERAL_POOL

use of com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL 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)

Aggregations

SystemSessionProperties.resourceOvercommit (com.facebook.presto.SystemSessionProperties.resourceOvercommit)1 QUEUED (com.facebook.presto.execution.QueryState.QUEUED)1 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)1 ClusterMemoryPool (com.facebook.presto.memory.ClusterMemoryPool)1 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)1 RESERVED_POOL (com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL)1 MemoryInfo (com.facebook.presto.memory.MemoryInfo)1 NodeMemoryConfig (com.facebook.presto.memory.NodeMemoryConfig)1 InternalNode (com.facebook.presto.metadata.InternalNode)1 InternalNodeManager (com.facebook.presto.metadata.InternalNodeManager)1 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)1 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)1 NodeStatus (com.facebook.presto.server.NodeStatus)1 QueryId (com.facebook.presto.spi.QueryId)1 ClusterMemoryPoolInfo (com.facebook.presto.spi.memory.ClusterMemoryPoolInfo)1 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)1 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1