Search in sources :

Example 16 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class ClusterMemoryManager method process.

public synchronized void process(Iterable<QueryExecution> queries) {
    if (!enabled) {
        return;
    }
    boolean outOfMemory = isClusterOutOfMemory();
    if (!outOfMemory) {
        lastTimeNotOutOfMemory = System.nanoTime();
    }
    boolean queryKilled = false;
    long totalBytes = 0;
    for (QueryExecution query : queries) {
        long bytes = query.getTotalMemoryReservation();
        DataSize sessionMaxQueryMemory = getQueryMaxMemory(query.getSession());
        long queryMemoryLimit = Math.min(maxQueryMemory.toBytes(), sessionMaxQueryMemory.toBytes());
        totalBytes += bytes;
        if (resourceOvercommit(query.getSession()) && outOfMemory) {
            // If a query has requested resource overcommit, only kill it if the cluster has run out of memory
            DataSize memory = succinctBytes(bytes);
            query.fail(new PrestoException(CLUSTER_OUT_OF_MEMORY, format("The cluster is out of memory and %s=true, so this query was killed. It was using %s of memory", RESOURCE_OVERCOMMIT, memory)));
            queryKilled = true;
        }
        if (!resourceOvercommit(query.getSession()) && bytes > queryMemoryLimit) {
            DataSize maxMemory = succinctBytes(queryMemoryLimit);
            query.fail(exceededGlobalLimit(maxMemory));
            queryKilled = true;
        }
    }
    clusterMemoryUsageBytes.set(totalBytes);
    if (killOnOutOfMemory) {
        boolean shouldKillQuery = nanosSince(lastTimeNotOutOfMemory).compareTo(killOnOutOfMemoryDelay) > 0 && outOfMemory;
        boolean lastKilledQueryIsGone = (lastKilledQuery == null);
        if (!lastKilledQueryIsGone) {
            ClusterMemoryPool generalPool = pools.get(GENERAL_POOL);
            if (generalPool != null) {
                lastKilledQueryIsGone = generalPool.getQueryMemoryReservations().containsKey(lastKilledQuery);
            }
        }
        if (shouldKillQuery && lastKilledQueryIsGone && !queryKilled) {
            // Kill the biggest query in the general pool
            QueryExecution biggestQuery = null;
            long maxMemory = -1;
            for (QueryExecution query : queries) {
                long bytesUsed = query.getTotalMemoryReservation();
                if (bytesUsed > maxMemory && query.getMemoryPool().getId().equals(GENERAL_POOL)) {
                    biggestQuery = query;
                    maxMemory = bytesUsed;
                }
            }
            if (biggestQuery != null) {
                biggestQuery.fail(new PrestoException(CLUSTER_OUT_OF_MEMORY, "The cluster is out of memory, and your query was killed. Please try again in a few minutes."));
                queriesKilledDueToOutOfMemory.incrementAndGet();
                lastKilledQuery = biggestQuery.getQueryId();
            }
        }
    }
    Map<MemoryPoolId, Integer> countByPool = new HashMap<>();
    for (QueryExecution query : queries) {
        MemoryPoolId id = query.getMemoryPool().getId();
        countByPool.put(id, countByPool.getOrDefault(id, 0) + 1);
    }
    updatePools(countByPool);
    updateNodes(updateAssignments(queries));
    // check if CPU usage is over limit
    for (QueryExecution query : queries) {
        Duration cpuTime = query.getTotalCpuTime();
        Duration sessionLimit = getQueryMaxCpuTime(query.getSession());
        Duration limit = maxQueryCpuTime.compareTo(sessionLimit) < 0 ? maxQueryCpuTime : sessionLimit;
        if (cpuTime.compareTo(limit) > 0) {
            query.fail(new ExceededCpuLimitException(limit));
        }
    }
}
Also used : HashMap(java.util.HashMap) DataSize(io.airlift.units.DataSize) PrestoException(com.facebook.presto.spi.PrestoException) Duration(io.airlift.units.Duration) ExceededCpuLimitException(com.facebook.presto.ExceededCpuLimitException) QueryExecution(com.facebook.presto.execution.QueryExecution) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId)

Example 17 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class ClientBuffer method loadPagesIfNecessary.

public void loadPagesIfNecessary(PagesSupplier pagesSupplier) {
    requireNonNull(pagesSupplier, "pagesSupplier is null");
    // Get the max size from the current pending read, which may not be the
    // same pending read instance by the time pages are loaded but this is
    // safe since the size is rechecked before returning pages.
    DataSize maxSize;
    synchronized (this) {
        if (pendingRead == null) {
            return;
        }
        maxSize = pendingRead.getMaxSize();
    }
    boolean dataAdded = loadPagesIfNecessary(pagesSupplier, maxSize);
    if (dataAdded) {
        PendingRead pendingRead;
        synchronized (this) {
            pendingRead = this.pendingRead;
        }
        if (pendingRead != null) {
            processRead(pendingRead);
        }
    }
}
Also used : DataSize(io.airlift.units.DataSize)

Example 18 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class InternalResourceGroup method getInfo.

public ResourceGroupInfo getInfo() {
    synchronized (root) {
        checkState(!subGroups.isEmpty() || (descendantRunningQueries == 0 && descendantQueuedQueries == 0), "Leaf resource group has descendant queries.");
        List<ResourceGroupInfo> infos = subGroups.values().stream().map(InternalResourceGroup::getInfo).collect(toImmutableList());
        ResourceGroupState resourceGroupState;
        if (canRunMore()) {
            resourceGroupState = CAN_RUN;
        } else if (canQueueMore()) {
            resourceGroupState = CAN_QUEUE;
        } else {
            resourceGroupState = FULL;
        }
        return new ResourceGroupInfo(id, new DataSize(softMemoryLimitBytes, BYTE), maxRunningQueries, maxQueuedQueries, resourceGroupState, eligibleSubGroups.size(), new DataSize(cachedMemoryUsageBytes, BYTE), runningQueries.size() + descendantRunningQueries, queuedQueries.size() + descendantQueuedQueries, infos);
    }
}
Also used : ResourceGroupState(com.facebook.presto.spi.resourceGroups.ResourceGroupState) DataSize(io.airlift.units.DataSize) ResourceGroupInfo(com.facebook.presto.spi.resourceGroups.ResourceGroupInfo)

Example 19 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class DriverContext method getDriverStats.

public DriverStats getDriverStats() {
    long totalScheduledTime = processWallNanos.get();
    long totalCpuTime = processCpuNanos.get();
    long totalUserTime = processUserNanos.get();
    long totalBlockedTime = blockedWallNanos.get();
    BlockedMonitor blockedMonitor = this.blockedMonitor.get();
    if (blockedMonitor != null) {
        totalBlockedTime += blockedMonitor.getBlockedTime();
    }
    List<OperatorStats> operators = ImmutableList.copyOf(transform(operatorContexts, OperatorContext::getOperatorStats));
    OperatorStats inputOperator = getFirst(operators, null);
    DataSize rawInputDataSize;
    long rawInputPositions;
    Duration rawInputReadTime;
    DataSize processedInputDataSize;
    long processedInputPositions;
    DataSize outputDataSize;
    long outputPositions;
    if (inputOperator != null) {
        rawInputDataSize = inputOperator.getInputDataSize();
        rawInputPositions = inputOperator.getInputPositions();
        rawInputReadTime = inputOperator.getAddInputWall();
        processedInputDataSize = inputOperator.getOutputDataSize();
        processedInputPositions = inputOperator.getOutputPositions();
        OperatorStats outputOperator = requireNonNull(getLast(operators, null));
        outputDataSize = outputOperator.getOutputDataSize();
        outputPositions = outputOperator.getOutputPositions();
    } else {
        rawInputDataSize = new DataSize(0, BYTE);
        rawInputPositions = 0;
        rawInputReadTime = new Duration(0, MILLISECONDS);
        processedInputDataSize = new DataSize(0, BYTE);
        processedInputPositions = 0;
        outputDataSize = new DataSize(0, BYTE);
        outputPositions = 0;
    }
    long startNanos = this.startNanos.get();
    if (startNanos < createNanos) {
        startNanos = System.nanoTime();
    }
    Duration queuedTime = new Duration(startNanos - createNanos, NANOSECONDS);
    long endNanos = this.endNanos.get();
    Duration elapsedTime;
    if (endNanos >= startNanos) {
        elapsedTime = new Duration(endNanos - createNanos, NANOSECONDS);
    } else {
        elapsedTime = new Duration(0, NANOSECONDS);
    }
    ImmutableSet.Builder<BlockedReason> builder = ImmutableSet.builder();
    for (OperatorStats operator : operators) {
        if (operator.getBlockedReason().isPresent()) {
            builder.add(operator.getBlockedReason().get());
        }
    }
    return new DriverStats(createdTime, executionStartTime.get(), executionEndTime.get(), queuedTime.convertToMostSuccinctTimeUnit(), elapsedTime.convertToMostSuccinctTimeUnit(), succinctBytes(memoryReservation.get()), succinctBytes(peakMemoryReservation.get()), succinctBytes(systemMemoryReservation.get()), new Duration(totalScheduledTime, NANOSECONDS).convertToMostSuccinctTimeUnit(), new Duration(totalCpuTime, NANOSECONDS).convertToMostSuccinctTimeUnit(), new Duration(totalUserTime, NANOSECONDS).convertToMostSuccinctTimeUnit(), new Duration(totalBlockedTime, NANOSECONDS).convertToMostSuccinctTimeUnit(), blockedMonitor != null, builder.build(), rawInputDataSize.convertToMostSuccinctDataSize(), rawInputPositions, rawInputReadTime, processedInputDataSize.convertToMostSuccinctDataSize(), processedInputPositions, outputDataSize.convertToMostSuccinctDataSize(), outputPositions, ImmutableList.copyOf(transform(operatorContexts, OperatorContext::getOperatorStats)));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration)

Example 20 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class TypedHistogram method addNewGroup.

private void addNewGroup(int hashPosition, int position, Block block, long count) {
    hashPositions.set(hashPosition, values.getPositionCount());
    counts.set(values.getPositionCount(), count);
    type.appendTo(block, position, values);
    // increase capacity, if necessary
    if (values.getPositionCount() >= maxFill) {
        rehash(maxFill * 2);
    }
    if (getEstimatedSize() > FOUR_MEGABYTES) {
        throw exceededLocalLimit(new DataSize(4, MEGABYTE));
    }
}
Also used : DataSize(io.airlift.units.DataSize)

Aggregations

DataSize (io.airlift.units.DataSize)114 Test (org.testng.annotations.Test)71 Duration (io.airlift.units.Duration)36 Page (com.facebook.presto.spi.Page)23 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)19 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)11 HashAggregationOperatorFactory (com.facebook.presto.operator.HashAggregationOperator.HashAggregationOperatorFactory)11 URI (java.net.URI)11 MockQueryExecution (com.facebook.presto.execution.MockQueryExecution)10 RootInternalResourceGroup (com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup)10 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)10 Type (com.facebook.presto.spi.type.Type)9 MaterializedResult (com.facebook.presto.testing.MaterializedResult)9 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)7 QueryId (com.facebook.presto.spi.QueryId)6 BufferResult (com.facebook.presto.execution.buffer.BufferResult)5 MetadataManager (com.facebook.presto.metadata.MetadataManager)5 TopNOperatorFactory (com.facebook.presto.operator.TopNOperator.TopNOperatorFactory)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ArrayList (java.util.ArrayList)5