Search in sources :

Example 6 with StageInfo

use of io.prestosql.execution.StageInfo in project hetu-core by openlookeng.

the class QueryMonitor method logQueryTimeline.

private static void logQueryTimeline(QueryInfo queryInfo) {
    try {
        QueryStats queryStats = queryInfo.getQueryStats();
        StageInfo outputStage = queryInfo.isRunningAsync() ? null : queryInfo.getOutputStage().orElse(null);
        DateTime queryStartTime = queryStats.getCreateTime();
        DateTime queryEndTime = queryStats.getEndTime();
        // query didn't finish cleanly
        if (queryStartTime == null || queryEndTime == null) {
            return;
        }
        // planning duration -- start to end of planning
        long planning = queryStats.getTotalPlanningTime().toMillis();
        long logicalPlanning = queryStats.getTotalLogicalPlanningTime().toMillis();
        long distributedPlanning = queryStats.getDistributedPlanningTime().toMillis();
        long physicalPlanning = queryStats.getAnalysisTime().toMillis() - logicalPlanning;
        long syntaxAnalysisTime = queryStats.getTotalSyntaxAnalysisTime().toMillis();
        // Time spent waiting for required no. of worker nodes to be present
        long waiting = queryStats.getResourceWaitingTime().toMillis();
        List<StageInfo> stages = StageInfo.getAllStages(queryInfo.getOutputStage());
        long firstTaskStartTime = queryEndTime.getMillis();
        long firstStageFirstTaskStartTime = queryEndTime.getMillis();
        long lastTaskStartTime = queryStartTime.getMillis() + planning;
        long lastTaskEndTime = queryStartTime.getMillis() + planning;
        for (StageInfo stage : stages) {
            for (TaskInfo taskInfo : stage.getTasks()) {
                TaskStats taskStats = taskInfo.getStats();
                DateTime firstStartTime = taskStats.getFirstStartTime();
                if (firstStartTime != null) {
                    firstStageFirstTaskStartTime = Math.min(firstStartTime.getMillis(), firstStageFirstTaskStartTime);
                }
                // only consider leaf stages for other stats.
                if (!stage.getSubStages().isEmpty()) {
                    continue;
                }
                firstStartTime = taskStats.getFirstStartTime();
                if (firstStartTime != null) {
                    firstTaskStartTime = Math.min(firstStartTime.getMillis(), firstTaskStartTime);
                }
                DateTime lastStartTime = taskStats.getLastStartTime();
                if (lastStartTime != null) {
                    lastTaskStartTime = max(lastStartTime.getMillis(), lastTaskStartTime);
                }
                DateTime endTime = taskStats.getEndTime();
                if (endTime != null) {
                    lastTaskEndTime = max(endTime.getMillis(), lastTaskEndTime);
                }
            }
        }
        long elapsed = max(queryEndTime.getMillis() - queryStartTime.getMillis(), 0);
        // scheduling time is starting from end of plan time to  start of first task execution corresponding to any first stage.
        long scheduling = max(firstStageFirstTaskStartTime - queryStartTime.getMillis() - planning, 0);
        // executionInitializationTime is starting from first task of first stage to first task of leaf stage.
        long executionInitializationTime = max(firstTaskStartTime - firstStageFirstTaskStartTime, 0);
        long running = max(lastTaskEndTime - firstTaskStartTime, 0);
        long finishing = max(queryEndTime.getMillis() - lastTaskEndTime, 0);
        int spilledNodes = globalUniqueNodes(outputStage, true).size();
        long spilledWriteTimeMillisPerNode = spilledNodes > 0 ? (queryStats.getSpilledWriteTime().toMillis() / spilledNodes) : 0;
        long spilledReadTimeMillisPerNode = spilledNodes > 0 ? (queryStats.getSpilledReadTime().toMillis() / spilledNodes) : 0;
        logQueryTimeline(queryInfo.getQueryId(), queryInfo.getSession().getTransactionId().map(TransactionId::toString).orElse(""), elapsed, syntaxAnalysisTime, planning, logicalPlanning, physicalPlanning, distributedPlanning, waiting, scheduling, executionInitializationTime, running, finishing, queryStartTime, queryEndTime, spilledWriteTimeMillisPerNode, spilledReadTimeMillisPerNode);
    } catch (Exception e) {
        log.error(e, "Error logging query timeline");
    }
}
Also used : TaskInfo(io.prestosql.execution.TaskInfo) QueryStats(io.prestosql.execution.QueryStats) StageInfo(io.prestosql.execution.StageInfo) TaskStats(io.prestosql.operator.TaskStats) DateTime(org.joda.time.DateTime) TransactionId(io.prestosql.transaction.TransactionId)

Example 7 with StageInfo

use of io.prestosql.execution.StageInfo in project hetu-core by openlookeng.

the class SqlQueryScheduler method buildStageInfo.

private StageInfo buildStageInfo(StageId stageId, Map<StageId, StageInfo> stageInfos) {
    StageInfo parent = stageInfos.get(stageId);
    checkArgument(parent != null, "No stageInfo for %s", parent);
    List<StageInfo> childStages = stageLinkages.get(stageId).getChildStageIds().stream().map(childStageId -> buildStageInfo(childStageId, stageInfos)).collect(toImmutableList());
    if (childStages.isEmpty()) {
        return parent;
    }
    return new StageInfo(parent.getStageId(), parent.getState(), parent.getSelf(), parent.getPlan(), parent.getTypes(), parent.getStageStats(), parent.getTasks(), childStages, parent.getTables(), parent.getFailureCause());
}
Also used : CANCELED(io.prestosql.execution.StageState.CANCELED) SCHEDULED(io.prestosql.execution.StageState.SCHEDULED) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) NO_NODES_AVAILABLE(io.prestosql.spi.StandardErrorCode.NO_NODES_AVAILABLE) FIXED_BROADCAST_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.FIXED_BROADCAST_DISTRIBUTION) StageExecutionPlan(io.prestosql.sql.planner.StageExecutionPlan) Map(java.util.Map) SystemSessionProperties.getWriterMinSize(io.prestosql.SystemSessionProperties.getWriterMinSize) HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TaskStatus(io.prestosql.execution.TaskStatus) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) LocationFactory(io.prestosql.execution.LocationFactory) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) StageState(io.prestosql.execution.StageState) ConnectorPartitionHandle(io.prestosql.spi.connector.ConnectorPartitionHandle) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) SetThreadName(io.airlift.concurrent.SetThreadName) Iterables(com.google.common.collect.Iterables) RESUMABLE_FAILURE(io.prestosql.execution.StageState.RESUMABLE_FAILURE) Supplier(java.util.function.Supplier) SCALED_WRITER_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.SCALED_WRITER_DISTRIBUTION) QueryStateMachine(io.prestosql.execution.QueryStateMachine) ArrayList(java.util.ArrayList) CatalogName.isInternalSystemConnector(io.prestosql.spi.connector.CatalogName.isInternalSystemConnector) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NodeTaskMap(io.prestosql.execution.NodeTaskMap) SplitSource(io.prestosql.split.SplitSource) FINISHED(io.prestosql.execution.StageState.FINISHED) StageId(io.prestosql.execution.StageId) InternalNode(io.prestosql.metadata.InternalNode) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) QuerySnapshotManager(io.prestosql.snapshot.QuerySnapshotManager) ResourceGroupInfo(io.prestosql.server.ResourceGroupInfo) PartitioningHandle(io.prestosql.sql.planner.PartitioningHandle) QueryState(io.prestosql.execution.QueryState) NodePartitionMap(io.prestosql.sql.planner.NodePartitionMap) SqlStageExecution.createSqlStageExecution(io.prestosql.execution.SqlStageExecution.createSqlStageExecution) SqlStageExecution(io.prestosql.execution.SqlStageExecution) ABORTED(io.prestosql.execution.StageState.ABORTED) FailureDetector(io.prestosql.failuredetector.FailureDetector) RemoteTask(io.prestosql.execution.RemoteTask) FAILED(io.prestosql.execution.StageState.FAILED) SystemSessionProperties(io.prestosql.SystemSessionProperties) BiFunction(java.util.function.BiFunction) SettableFuture(com.google.common.util.concurrent.SettableFuture) SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler(io.prestosql.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler) Duration(io.airlift.units.Duration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) Collectors.toSet(java.util.stream.Collectors.toSet) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) CatalogName(io.prestosql.spi.connector.CatalogName) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RemoteTaskFactory(io.prestosql.execution.RemoteTaskFactory) UUID(java.util.UUID) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) SOURCE_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) StageInfo(io.prestosql.execution.StageInfo) Entry(java.util.Map.Entry) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) MoreFutures.whenAnyComplete(io.airlift.concurrent.MoreFutures.whenAnyComplete) BasicStageStats(io.prestosql.execution.BasicStageStats) NodePartitioningManager(io.prestosql.sql.planner.NodePartitioningManager) NOT_PARTITIONED(io.prestosql.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED) RUNNING(io.prestosql.execution.StageState.RUNNING) TaskId(io.prestosql.execution.TaskId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) HashMap(java.util.HashMap) OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) TaskLocation(io.prestosql.operator.TaskLocation) HashSet(java.util.HashSet) SnapshotConfig.calculateTaskCount(io.prestosql.snapshot.SnapshotConfig.calculateTaskCount) ImmutableList(com.google.common.collect.ImmutableList) SystemSessionProperties.isReuseTableScanEnabled(io.prestosql.SystemSessionProperties.isReuseTableScanEnabled) OutputBufferId(io.prestosql.execution.buffer.OutputBuffers.OutputBufferId) Verify.verify(com.google.common.base.Verify.verify) Failures.checkCondition(io.prestosql.util.Failures.checkCondition) Objects.requireNonNull(java.util.Objects.requireNonNull) TimeStat(io.airlift.stats.TimeStat) REPLICATE(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPLICATE) ExecutorService(java.util.concurrent.ExecutorService) Ints(com.google.common.primitives.Ints) DynamicFilterService(io.prestosql.dynamicfilter.DynamicFilterService) MoreFutures.tryGetFutureValue(io.airlift.concurrent.MoreFutures.tryGetFutureValue) SystemSessionProperties.getConcurrentLifespansPerNode(io.prestosql.SystemSessionProperties.getConcurrentLifespansPerNode) Collectors.toList(java.util.stream.Collectors.toList) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) BasicStageStats.aggregateBasicStageStats(io.prestosql.execution.BasicStageStats.aggregateBasicStageStats) StageInfo(io.prestosql.execution.StageInfo)

Example 8 with StageInfo

use of io.prestosql.execution.StageInfo in project hetu-core by openlookeng.

the class StatsAndCosts method reconstructStatsAndCosts.

private static void reconstructStatsAndCosts(StageInfo stage, ImmutableMap.Builder<PlanNodeId, PlanNodeStatsEstimate> planNodeStats, ImmutableMap.Builder<PlanNodeId, PlanCostEstimate> planNodeCosts, Set<PlanNodeId> visitedPlanNodeId) {
    PlanFragment planFragment = stage.getPlan();
    if (planFragment != null) {
        if (!visitedPlanNodeId.contains(planFragment.getRoot().getId())) {
            visitedPlanNodeId.add(planFragment.getRoot().getId());
            planNodeStats.putAll(planFragment.getStatsAndCosts().getStats());
            planNodeCosts.putAll(planFragment.getStatsAndCosts().getCosts());
        }
    }
    for (StageInfo subStage : stage.getSubStages()) {
        reconstructStatsAndCosts(subStage, planNodeStats, planNodeCosts, visitedPlanNodeId);
    }
}
Also used : StageInfo(io.prestosql.execution.StageInfo) PlanFragment(io.prestosql.sql.planner.PlanFragment)

Example 9 with StageInfo

use of io.prestosql.execution.StageInfo in project hetu-core by openlookeng.

the class Query method toStageStats.

private static StageStats toStageStats(StageInfo stageInfo) {
    if (stageInfo == null) {
        return null;
    }
    io.prestosql.execution.StageStats stageStats = stageInfo.getStageStats();
    ImmutableList.Builder<StageStats> subStages = ImmutableList.builder();
    for (StageInfo subStage : stageInfo.getSubStages()) {
        subStages.add(toStageStats(subStage));
    }
    Set<String> uniqueNodes = new HashSet<>();
    for (TaskInfo task : stageInfo.getTasks()) {
        // todo add nodeId to TaskInfo
        URI uri = task.getTaskStatus().getSelf();
        uniqueNodes.add(uri.getHost() + ":" + uri.getPort());
    }
    return StageStats.builder().setStageId(String.valueOf(stageInfo.getStageId().getId())).setState(stageInfo.getState().toString()).setDone(stageInfo.getState().isDone()).setNodes(uniqueNodes.size()).setTotalSplits(stageStats.getTotalDrivers()).setQueuedSplits(stageStats.getQueuedDrivers()).setRunningSplits(stageStats.getRunningDrivers() + stageStats.getBlockedDrivers()).setCompletedSplits(stageStats.getCompletedDrivers()).setCpuTimeMillis(stageStats.getTotalCpuTime().toMillis()).setWallTimeMillis(stageStats.getTotalScheduledTime().toMillis()).setProcessedRows(stageStats.getRawInputPositions()).setProcessedBytes(stageStats.getRawInputDataSize().toBytes()).setSubStages(subStages.build()).build();
}
Also used : TaskInfo(io.prestosql.execution.TaskInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StageStats(io.prestosql.client.StageStats) StageInfo(io.prestosql.execution.StageInfo) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

StageInfo (io.prestosql.execution.StageInfo)9 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 Verify.verify (com.google.common.base.Verify.verify)3 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3 Iterables (com.google.common.collect.Iterables)3 Duration (io.airlift.units.Duration)3 Session (io.prestosql.Session)3 CaseFormat (com.google.common.base.CaseFormat)2 UPPER_UNDERSCORE (com.google.common.base.CaseFormat.UPPER_UNDERSCORE)2 Functions (com.google.common.base.Functions)2 Joiner (com.google.common.base.Joiner)2 Lists (com.google.common.collect.Lists)2 Streams (com.google.common.collect.Streams)2 PlanCostEstimate (io.prestosql.cost.PlanCostEstimate)2 PlanNodeStatsEstimate (io.prestosql.cost.PlanNodeStatsEstimate)2 StatsAndCosts (io.prestosql.cost.StatsAndCosts)2