Search in sources :

Example 1 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class TotalReservationOnBlockedNodesLowMemoryKiller method chooseWholeQueryToKill.

private Optional<KillTarget> chooseWholeQueryToKill(List<MemoryInfo> nodes) {
    Map<QueryId, Long> memoryReservationOnBlockedNodes = new HashMap<>();
    for (MemoryInfo node : nodes) {
        MemoryPoolInfo memoryPool = node.getPool();
        if (memoryPool == null) {
            continue;
        }
        if (memoryPool.getFreeBytes() + memoryPool.getReservedRevocableBytes() > 0) {
            continue;
        }
        Map<QueryId, Long> queryMemoryReservations = memoryPool.getQueryMemoryReservations();
        queryMemoryReservations.forEach((queryId, memoryReservation) -> {
            memoryReservationOnBlockedNodes.compute(queryId, (id, oldValue) -> oldValue == null ? memoryReservation : oldValue + memoryReservation);
        });
    }
    return memoryReservationOnBlockedNodes.entrySet().stream().max(comparingLong(Map.Entry::getValue)).map(Map.Entry::getKey).map(KillTarget::wholeQuery);
}
Also used : TaskMemoryInfo(io.trino.TaskMemoryInfo) HashMap(java.util.HashMap) QueryId(io.trino.spi.QueryId) Comparator.comparingLong(java.util.Comparator.comparingLong) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class TotalReservationOnBlockedNodesLowMemoryKiller method chooseTasksToKill.

private Optional<KillTarget> chooseTasksToKill(List<MemoryInfo> nodes) {
    ImmutableSet.Builder<TaskId> tasksToKillBuilder = ImmutableSet.builder();
    for (MemoryInfo node : nodes) {
        MemoryPoolInfo memoryPool = node.getPool();
        if (memoryPool == null) {
            continue;
        }
        if (memoryPool.getFreeBytes() + memoryPool.getReservedRevocableBytes() > 0) {
            continue;
        }
        node.getTasksMemoryInfo().values().stream().max(comparing(TaskMemoryInfo::getMemoryReservation)).map(TaskMemoryInfo::getTaskId).ifPresent(tasksToKillBuilder::add);
    }
    Set<TaskId> tasksToKill = tasksToKillBuilder.build();
    if (tasksToKill.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(KillTarget.selectedTasks(tasksToKill));
}
Also used : TaskMemoryInfo(io.trino.TaskMemoryInfo) TaskId(io.trino.execution.TaskId) ImmutableSet(com.google.common.collect.ImmutableSet) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo)

Example 3 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class ClusterMemoryManager method updateMemoryPool.

private synchronized void updateMemoryPool(int queryCount) {
    // Update view of cluster memory and pools
    List<MemoryInfo> nodeMemoryInfos = nodes.values().stream().map(RemoteNodeMemory::getInfo).filter(Optional::isPresent).map(Optional::get).collect(toImmutableList());
    long totalProcessors = nodeMemoryInfos.stream().mapToLong(MemoryInfo::getAvailableProcessors).sum();
    totalAvailableProcessors.set(totalProcessors);
    long totalClusterMemory = nodeMemoryInfos.stream().mapToLong(memoryInfo -> memoryInfo.getPool().getMaxBytes()).sum();
    clusterMemoryBytes.set(totalClusterMemory);
    pool.update(nodeMemoryInfos, queryCount);
    if (!changeListeners.isEmpty()) {
        MemoryPoolInfo info = pool.getInfo();
        for (Consumer<MemoryPoolInfo> listener : changeListeners) {
            listenerExecutor.execute(() -> listener.accept(info));
        }
    }
}
Also used : QueryMemoryInfo(io.trino.memory.LowMemoryKiller.QueryMemoryInfo) SystemSessionProperties.getQueryMaxTotalMemory(io.trino.SystemSessionProperties.getQueryMaxTotalMemory) QueryId(io.trino.spi.QueryId) RESOURCE_OVERCOMMIT(io.trino.SystemSessionProperties.RESOURCE_OVERCOMMIT) QueryIdGenerator(io.trino.execution.QueryIdGenerator) BasicQueryInfo(io.trino.server.BasicQueryInfo) SystemSessionProperties.resourceOvercommit(io.trino.SystemSessionProperties.resourceOvercommit) CLUSTER_OUT_OF_MEMORY(io.trino.spi.StandardErrorCode.CLUSTER_OUT_OF_MEMORY) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) Duration(io.airlift.units.Duration) ClusterMemoryPoolManager(io.trino.spi.memory.ClusterMemoryPoolManager) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Map(java.util.Map) SystemSessionProperties.getQueryMaxMemory(io.trino.SystemSessionProperties.getQueryMaxMemory) QueryExecution(io.trino.execution.QueryExecution) SHUTTING_DOWN(io.trino.metadata.NodeState.SHUTTING_DOWN) ImmutableSet(com.google.common.collect.ImmutableSet) ACTIVE(io.trino.metadata.NodeState.ACTIVE) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) Math.min(java.lang.Math.min) Streams(com.google.common.collect.Streams) GuardedBy(javax.annotation.concurrent.GuardedBy) TaskId(io.trino.execution.TaskId) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DataSize(io.airlift.units.DataSize) List(java.util.List) LocationFactory(io.trino.execution.LocationFactory) TaskInfo(io.trino.execution.TaskInfo) Entry(java.util.Map.Entry) Optional(java.util.Optional) JmxException(org.weakref.jmx.JmxException) Joiner(com.google.common.base.Joiner) JsonCodec(io.airlift.json.JsonCodec) HttpClient(io.airlift.http.client.HttpClient) Iterables(com.google.common.collect.Iterables) InternalNodeManager(io.trino.metadata.InternalNodeManager) Logger(io.airlift.log.Logger) QueryMemoryInfo(io.trino.memory.LowMemoryKiller.QueryMemoryInfo) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) 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) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ExecutorService(java.util.concurrent.ExecutorService) ServerConfig(io.trino.server.ServerConfig) StageInfo(io.trino.execution.StageInfo) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) IOException(java.io.IOException) TaskStatus(io.trino.execution.TaskStatus) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) InternalNode(io.trino.metadata.InternalNode) ExceededMemoryLimitException.exceededGlobalTotalLimit(io.trino.ExceededMemoryLimitException.exceededGlobalTotalLimit) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MBeanExporter(org.weakref.jmx.MBeanExporter) ExceededMemoryLimitException.exceededGlobalUserLimit(io.trino.ExceededMemoryLimitException.exceededGlobalUserLimit) Optional(java.util.Optional) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo)

Example 4 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class ClusterMemoryPool method update.

public synchronized void update(List<MemoryInfo> memoryInfos, int assignedQueries) {
    nodes = 0;
    blockedNodes = 0;
    totalDistributedBytes = 0;
    reservedDistributedBytes = 0;
    reservedRevocableDistributedBytes = 0;
    this.assignedQueries = assignedQueries;
    this.queryMemoryReservations.clear();
    this.queryMemoryAllocations.clear();
    this.queryMemoryRevocableReservations.clear();
    for (MemoryInfo info : memoryInfos) {
        MemoryPoolInfo poolInfo = info.getPool();
        nodes++;
        if (poolInfo.getFreeBytes() + poolInfo.getReservedRevocableBytes() <= 0) {
            blockedNodes++;
        }
        totalDistributedBytes += poolInfo.getMaxBytes();
        reservedDistributedBytes += poolInfo.getReservedBytes();
        reservedRevocableDistributedBytes += poolInfo.getReservedRevocableBytes();
        for (Map.Entry<QueryId, Long> entry : poolInfo.getQueryMemoryReservations().entrySet()) {
            queryMemoryReservations.merge(entry.getKey(), entry.getValue(), Long::sum);
        }
        for (Map.Entry<QueryId, List<MemoryAllocation>> entry : poolInfo.getQueryMemoryAllocations().entrySet()) {
            queryMemoryAllocations.merge(entry.getKey(), entry.getValue(), this::mergeQueryAllocations);
        }
        for (Map.Entry<QueryId, Long> entry : poolInfo.getQueryMemoryRevocableReservations().entrySet()) {
            queryMemoryRevocableReservations.merge(entry.getKey(), entry.getValue(), Long::sum);
        }
    }
}
Also used : QueryId(io.trino.spi.QueryId) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class TestFullNodeCapableNodeAllocator method setupNodeAllocatorService.

private void setupNodeAllocatorService(InMemoryNodeManager nodeManager, int maxFullNodesPerQuery) {
    // just in case
    shutdownNodeAllocatorService();
    MemoryInfo memoryInfo = new MemoryInfo(4, new MemoryPoolInfo(DataSize.of(64, GIGABYTE).toBytes(), 0, 0, ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of()));
    Map<String, Optional<MemoryInfo>> workerMemoryInfos = ImmutableMap.of(NODE_1.getNodeIdentifier(), Optional.of(memoryInfo), NODE_2.getNodeIdentifier(), Optional.of(memoryInfo), NODE_3.getNodeIdentifier(), Optional.of(memoryInfo), NODE_4.getNodeIdentifier(), Optional.of(memoryInfo));
    nodeAllocatorService = new FullNodeCapableNodeAllocatorService(nodeManager, () -> workerMemoryInfos, maxFullNodesPerQuery, 1.0, false);
    nodeAllocatorService.start();
}
Also used : MemoryInfo(io.trino.memory.MemoryInfo) Optional(java.util.Optional) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo)

Aggregations

MemoryPoolInfo (io.trino.spi.memory.MemoryPoolInfo)8 QueryId (io.trino.spi.QueryId)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TaskMemoryInfo (io.trino.TaskMemoryInfo)3 TaskId (io.trino.execution.TaskId)3 List (java.util.List)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Iterables (com.google.common.collect.Iterables)1