Search in sources :

Example 1 with ClusterMemoryPoolInfo

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

the class ClusterMemoryManager method findLargestMemoryQuery.

private QueryExecution findLargestMemoryQuery(ClusterMemoryPoolInfo generalPool, Iterable<QueryExecution> queries) {
    QueryExecution biggestQuery = null;
    long maxMemory = -1;
    Optional<QueryId> largestMemoryQuery = generalPool.getLargestMemoryQuery();
    // If present, this means the resource manager is determining the largest query, so do not make this determination locally
    if (memoryManagerService.isPresent()) {
        return largestMemoryQuery.flatMap(largestMemoryQueryId -> Streams.stream(queries).filter(query -> query.getQueryId().equals(largestMemoryQueryId)).findFirst()).orElse(null);
    }
    for (QueryExecution queryExecution : queries) {
        if (resourceOvercommit(queryExecution.getSession())) {
            // since their memory usage is unbounded.
            continue;
        }
        long bytesUsed = getQueryMemoryReservation(queryExecution);
        if (bytesUsed > maxMemory) {
            biggestQuery = queryExecution;
            maxMemory = bytesUsed;
        }
    }
    return biggestQuery;
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) SYSTEM(com.facebook.presto.execution.QueryLimit.Source.SYSTEM) QUERY(com.facebook.presto.execution.QueryLimit.Source.QUERY) Duration(io.airlift.units.Duration) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) QueryMemoryInfo(com.facebook.presto.memory.LowMemoryKiller.QueryMemoryInfo) QueryLimit.getMinimum(com.facebook.presto.execution.QueryLimit.getMinimum) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Map(java.util.Map) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) ServerConfig(com.facebook.presto.server.ServerConfig) QueryLimit(com.facebook.presto.execution.QueryLimit) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ExceededMemoryLimitException.exceededGlobalUserLimit(com.facebook.presto.ExceededMemoryLimitException.exceededGlobalUserLimit) Math.min(java.lang.Math.min) Streams(com.google.common.collect.Streams) GuardedBy(javax.annotation.concurrent.GuardedBy) Codec(com.facebook.airlift.json.Codec) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) QueryIdGenerator(com.facebook.presto.execution.QueryIdGenerator) QueryExecution(com.facebook.presto.execution.QueryExecution) DataSize(io.airlift.units.DataSize) List(java.util.List) Stream(java.util.stream.Stream) Comparator.comparingLong(java.util.Comparator.comparingLong) Entry(java.util.Map.Entry) Optional(java.util.Optional) JmxException(org.weakref.jmx.JmxException) RESOURCE_GROUP(com.facebook.presto.execution.QueryLimit.Source.RESOURCE_GROUP) SystemSessionProperties.resourceOvercommit(com.facebook.presto.SystemSessionProperties.resourceOvercommit) Joiner(com.google.common.base.Joiner) QueryLimit.createDataSizeLimit(com.facebook.presto.execution.QueryLimit.createDataSizeLimit) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) RESOURCE_OVERCOMMIT(com.facebook.presto.SystemSessionProperties.RESOURCE_OVERCOMMIT) Logger(com.facebook.airlift.log.Logger) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) CLUSTER_OUT_OF_MEMORY(com.facebook.presto.spi.StandardErrorCode.CLUSTER_OUT_OF_MEMORY) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ResourceGroupQueryLimits(com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits) SystemSessionProperties.getQueryMaxTotalMemory(com.facebook.presto.SystemSessionProperties.getQueryMaxTotalMemory) ImmutableList(com.google.common.collect.ImmutableList) Managed(org.weakref.jmx.Managed) Closer(com.google.common.io.Closer) Verify.verify(com.google.common.base.Verify.verify) SmileCodec(com.facebook.airlift.json.smile.SmileCodec) Objects.requireNonNull(java.util.Objects.requireNonNull) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SystemSessionProperties.getQueryMaxMemory(com.facebook.presto.SystemSessionProperties.getQueryMaxMemory) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SimpleEntry(java.util.AbstractMap.SimpleEntry) ExecutorService(java.util.concurrent.ExecutorService) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) ClusterMemoryPoolManager(com.facebook.presto.spi.memory.ClusterMemoryPoolManager) ObjectNames.generatedNameOf(org.weakref.jmx.ObjectNames.generatedNameOf) SHUTTING_DOWN(com.facebook.presto.spi.NodeState.SHUTTING_DOWN) InternalCommunicationConfig(com.facebook.presto.server.InternalCommunicationConfig) IOException(java.io.IOException) LocationFactory(com.facebook.presto.execution.LocationFactory) HttpClient(com.facebook.airlift.http.client.HttpClient) ExceededMemoryLimitException.exceededGlobalTotalLimit(com.facebook.presto.ExceededMemoryLimitException.exceededGlobalTotalLimit) InternalNode(com.facebook.presto.metadata.InternalNode) Consumer(java.util.function.Consumer) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MBeanExporter(org.weakref.jmx.MBeanExporter) Comparator(java.util.Comparator) ClusterMemoryManagerService(com.facebook.presto.resourcemanager.ClusterMemoryManagerService) QueryId(com.facebook.presto.spi.QueryId) QueryExecution(com.facebook.presto.execution.QueryExecution)

Example 2 with ClusterMemoryPoolInfo

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

the class ClusterMemoryManager method updateAssignments.

// TODO once the reserved pool is removed we can remove this method. We can also update
// RemoteNodeMemory as we don't need to POST anything.
private synchronized MemoryPoolAssignmentsRequest updateAssignments(Iterable<QueryExecution> queries) {
    ClusterMemoryPoolInfo reservedPool = getClusterInfo(RESERVED_POOL);
    ClusterMemoryPoolInfo generalPool = getClusterInfo(GENERAL_POOL);
    verify(generalPool != null, "generalPool is null");
    verify(reservedPool != null, "reservedPool is null");
    long version = memoryPoolAssignmentsVersion.incrementAndGet();
    // and is more of a safety check than a guarantee
    if (allAssignmentsHavePropagated(queries)) {
        if (reservedPool.getAssignedQueries() == 0 && generalPool.getBlockedNodes() > 0) {
            QueryExecution biggestQuery = findLargestMemoryQuery(generalPool, queries);
            if (biggestQuery != null) {
                log.info("Moving query %s to the reserved pool", biggestQuery.getQueryId());
                biggestQuery.setMemoryPool(new VersionedMemoryPoolId(RESERVED_POOL, version));
            }
        }
    }
    ImmutableList.Builder<MemoryPoolAssignment> assignments = ImmutableList.builder();
    for (QueryExecution queryExecution : queries) {
        assignments.add(new MemoryPoolAssignment(queryExecution.getQueryId(), queryExecution.getMemoryPool().getId()));
    }
    return new MemoryPoolAssignmentsRequest(coordinatorId, version, assignments.build());
}
Also used : ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) QueryExecution(com.facebook.presto.execution.QueryExecution)

Example 3 with ClusterMemoryPoolInfo

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

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 4 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 5 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)

Aggregations

ClusterMemoryPoolInfo (com.facebook.presto.spi.memory.ClusterMemoryPoolInfo)6 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)3 QueryId (com.facebook.presto.spi.QueryId)3 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 SystemSessionProperties.resourceOvercommit (com.facebook.presto.SystemSessionProperties.resourceOvercommit)2 QueryExecution (com.facebook.presto.execution.QueryExecution)2 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)2 RESERVED_POOL (com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL)2 InternalNode (com.facebook.presto.metadata.InternalNode)2 InternalNodeManager (com.facebook.presto.metadata.InternalNodeManager)2 Collection (java.util.Collection)2 HttpClient (com.facebook.airlift.http.client.HttpClient)1 Codec (com.facebook.airlift.json.Codec)1 JsonCodec (com.facebook.airlift.json.JsonCodec)1 SmileCodec (com.facebook.airlift.json.smile.SmileCodec)1 Logger (com.facebook.airlift.log.Logger)1 ExceededMemoryLimitException.exceededGlobalTotalLimit (com.facebook.presto.ExceededMemoryLimitException.exceededGlobalTotalLimit)1 ExceededMemoryLimitException.exceededGlobalUserLimit (com.facebook.presto.ExceededMemoryLimitException.exceededGlobalUserLimit)1