Search in sources :

Example 1 with StageInfo

use of com.facebook.presto.execution.StageInfo in project presto by prestodb.

the class QueryMonitor method logQueryTimeline.

private static void logQueryTimeline(QueryInfo queryInfo) {
    try {
        QueryStats queryStats = queryInfo.getQueryStats();
        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() == null ? 0 : queryStats.getTotalPlanningTime().toMillis();
        List<StageInfo> stages = StageInfo.getAllStages(queryInfo.getOutputStage());
        // long lastSchedulingCompletion = 0;
        long firstTaskStartTime = queryEndTime.getMillis();
        long lastTaskStartTime = queryStartTime.getMillis() + planning;
        long lastTaskEndTime = queryStartTime.getMillis() + planning;
        for (StageInfo stage : stages) {
            // only consider leaf stages
            if (!stage.getSubStages().isEmpty()) {
                continue;
            }
            for (TaskInfo taskInfo : stage.getTasks()) {
                TaskStats taskStats = taskInfo.getStats();
                DateTime 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 = queryEndTime.getMillis() - queryStartTime.getMillis();
        long scheduling = firstTaskStartTime - queryStartTime.getMillis() - planning;
        long running = lastTaskEndTime - firstTaskStartTime;
        long finishing = queryEndTime.getMillis() - lastTaskEndTime;
        log.info("TIMELINE: Query %s :: Transaction:[%s] :: elapsed %sms :: planning %sms :: scheduling %sms :: running %sms :: finishing %sms :: begin %s :: end %s", queryInfo.getQueryId(), queryInfo.getSession().getTransactionId().map(TransactionId::toString).orElse(""), max(elapsed, 0), max(planning, 0), max(scheduling, 0), max(running, 0), max(finishing, 0), queryStartTime, queryEndTime);
    } catch (Exception e) {
        log.error(e, "Error logging query timeline");
    }
}
Also used : TaskInfo(com.facebook.presto.execution.TaskInfo) QueryStats(com.facebook.presto.execution.QueryStats) StageInfo(com.facebook.presto.execution.StageInfo) TaskStats(com.facebook.presto.operator.TaskStats) DateTime(org.joda.time.DateTime) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TransactionId(com.facebook.presto.transaction.TransactionId)

Example 2 with StageInfo

use of com.facebook.presto.execution.StageInfo in project presto by prestodb.

the class PlanPrinter method textDistributedPlan.

public static String textDistributedPlan(List<StageInfo> stages, Metadata metadata, Session session) {
    StringBuilder builder = new StringBuilder();
    List<StageInfo> allStages = stages.stream().flatMap(stage -> getAllStages(Optional.of(stage)).stream()).collect(toImmutableList());
    for (StageInfo stageInfo : allStages) {
        Map<PlanNodeId, PlanNodeStats> aggregatedStats = new HashMap<>();
        List<PlanNodeStats> planNodeStats = stageInfo.getTasks().stream().map(TaskInfo::getStats).flatMap(taskStats -> getPlanNodeStats(taskStats).stream()).collect(toList());
        for (PlanNodeStats stats : planNodeStats) {
            aggregatedStats.merge(stats.getPlanNodeId(), stats, PlanNodeStats::merge);
        }
        builder.append(formatFragment(metadata, session, stageInfo.getPlan(), Optional.of(stageInfo.getStageStats()), Optional.of(aggregatedStats)));
    }
    return builder.toString();
}
Also used : ComparisonExpressionType(com.facebook.presto.sql.tree.ComparisonExpressionType) Arrays(java.util.Arrays) FrameBound(com.facebook.presto.sql.tree.FrameBound) DistinctLimitNode(com.facebook.presto.sql.planner.plan.DistinctLimitNode) OperatorStats(com.facebook.presto.operator.OperatorStats) StageInfo(com.facebook.presto.execution.StageInfo) MarkDistinctNode(com.facebook.presto.sql.planner.plan.MarkDistinctNode) Map(java.util.Map) IndexJoinNode(com.facebook.presto.sql.planner.plan.IndexJoinNode) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) Double.max(java.lang.Double.max) StageInfo.getAllStages(com.facebook.presto.execution.StageInfo.getAllStages) StageStats(com.facebook.presto.execution.StageStats) RowNumberNode(com.facebook.presto.sql.planner.plan.RowNumberNode) Set(java.util.Set) VARCHAR(com.facebook.presto.spi.type.VarcharType.VARCHAR) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ExceptNode(com.facebook.presto.sql.planner.plan.ExceptNode) Domain(com.facebook.presto.spi.predicate.Domain) Stream(java.util.stream.Stream) OperatorNotFoundException(com.facebook.presto.metadata.OperatorNotFoundException) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode) AssignUniqueId(com.facebook.presto.sql.planner.plan.AssignUniqueId) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode) Lists.reverse(com.google.common.collect.Lists.reverse) Joiner(com.google.common.base.Joiner) Iterables(com.google.common.collect.Iterables) SINGLE_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) Slice(io.airlift.slice.Slice) GroupIdNode(com.facebook.presto.sql.planner.plan.GroupIdNode) DomainUtils.simplifyDomain(com.facebook.presto.sql.planner.DomainUtils.simplifyDomain) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) ArrayList(java.util.ArrayList) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Type(com.facebook.presto.spi.type.Type) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Functions(com.google.common.base.Functions) PipelineStats(com.facebook.presto.operator.PipelineStats) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) Session(com.facebook.presto.Session) Throwables(com.google.common.base.Throwables) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Range(com.facebook.presto.spi.predicate.Range) Math.sqrt(java.lang.Math.sqrt) ColumnHandle(com.facebook.presto.spi.ColumnHandle) FunctionInvoker(com.facebook.presto.sql.FunctionInvoker) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) FilterNode(com.facebook.presto.sql.planner.plan.FilterNode) TaskInfo(com.facebook.presto.execution.TaskInfo) Metadata(com.facebook.presto.metadata.Metadata) TaskStats(com.facebook.presto.operator.TaskStats) ExplainAnalyzeNode(com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) SortNode(com.facebook.presto.sql.planner.plan.SortNode) MetadataDeleteNode(com.facebook.presto.sql.planner.plan.MetadataDeleteNode) TableWriterNode(com.facebook.presto.sql.planner.plan.TableWriterNode) ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) Duration(io.airlift.units.Duration) GraphvizPrinter(com.facebook.presto.util.GraphvizPrinter) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toMap(java.util.stream.Collectors.toMap) Locale(java.util.Locale) TopNRowNumberNode(com.facebook.presto.sql.planner.plan.TopNRowNumberNode) IndexSourceNode(com.facebook.presto.sql.planner.plan.IndexSourceNode) TopNNode(com.facebook.presto.sql.planner.plan.TopNNode) Assignments(com.facebook.presto.sql.planner.plan.Assignments) NullableValue(com.facebook.presto.spi.predicate.NullableValue) DataSize.succinctDataSize(io.airlift.units.DataSize.succinctDataSize) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ImmutableSet(com.google.common.collect.ImmutableSet) Scope(com.facebook.presto.sql.planner.plan.ExchangeNode.Scope) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Iterables.getLast(com.google.common.collect.Iterables.getLast) Marker(com.facebook.presto.spi.predicate.Marker) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) DataSize(io.airlift.units.DataSize) List(java.util.List) Window(com.facebook.presto.sql.tree.Window) SampleNode(com.facebook.presto.sql.planner.plan.SampleNode) Optional(java.util.Optional) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) HashMap(java.util.HashMap) HashSet(java.util.HashSet) WindowFrame(com.facebook.presto.sql.tree.WindowFrame) PlanVisitor(com.facebook.presto.sql.planner.plan.PlanVisitor) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Double.isFinite(java.lang.Double.isFinite) LinkedList(java.util.LinkedList) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode) UnnestNode(com.facebook.presto.sql.planner.plan.UnnestNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Collections.emptyMap(java.util.Collections.emptyMap) TableLayout(com.facebook.presto.metadata.TableLayout) CaseFormat(com.google.common.base.CaseFormat) Signature(com.facebook.presto.metadata.Signature) HashCollisionsInfo(com.facebook.presto.operator.HashCollisionsInfo) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) UPPER_UNDERSCORE(com.google.common.base.CaseFormat.UPPER_UNDERSCORE) Collectors.toList(java.util.stream.Collectors.toList) UnionNode(com.facebook.presto.sql.planner.plan.UnionNode) Expression(com.facebook.presto.sql.tree.Expression) TableHandle(com.facebook.presto.metadata.TableHandle) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode) BYTE(io.airlift.units.DataSize.Unit.BYTE) IntersectNode(com.facebook.presto.sql.planner.plan.IntersectNode) EnforceSingleRowNode(com.facebook.presto.sql.planner.plan.EnforceSingleRowNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) TaskInfo(com.facebook.presto.execution.TaskInfo) HashMap(java.util.HashMap) StageInfo(com.facebook.presto.execution.StageInfo)

Example 3 with StageInfo

use of com.facebook.presto.execution.StageInfo in project presto by prestodb.

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.getFailureCause());
}
Also used : OutputBuffers(com.facebook.presto.OutputBuffers) StageExecutionPlan(com.facebook.presto.sql.planner.StageExecutionPlan) SCHEDULED(com.facebook.presto.execution.StageState.SCHEDULED) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) GENERIC_INTERNAL_ERROR(com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) CANCELED(com.facebook.presto.execution.StageState.CANCELED) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) Duration(io.airlift.units.Duration) OutputBufferId(com.facebook.presto.OutputBuffers.OutputBufferId) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) StageInfo(com.facebook.presto.execution.StageInfo) Node(com.facebook.presto.spi.Node) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FAILED(com.facebook.presto.execution.StageState.FAILED) Map(java.util.Map) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) URI(java.net.URI) FIXED_BROADCAST_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.FIXED_BROADCAST_DISTRIBUTION) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) SplitSource(com.facebook.presto.split.SplitSource) RemoteTaskFactory(com.facebook.presto.execution.RemoteTaskFactory) ImmutableCollectors.toImmutableMap(com.facebook.presto.util.ImmutableCollectors.toImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) NO_NODES_AVAILABLE(com.facebook.presto.spi.StandardErrorCode.NO_NODES_AVAILABLE) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) SOURCE_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) String.format(java.lang.String.format) StageState(com.facebook.presto.execution.StageState) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) MoreFutures.whenAnyComplete(io.airlift.concurrent.MoreFutures.whenAnyComplete) ConnectorId(com.facebook.presto.connector.ConnectorId) SetThreadName(io.airlift.concurrent.SetThreadName) StageId(com.facebook.presto.execution.StageId) Iterables(com.google.common.collect.Iterables) NodePartitionMap(com.facebook.presto.sql.planner.NodePartitionMap) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) RUNNING(com.facebook.presto.execution.StageState.RUNNING) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) TimeStat(io.airlift.stats.TimeStat) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ExecutorService(java.util.concurrent.ExecutorService) Failures.checkCondition(com.facebook.presto.util.Failures.checkCondition) NodePartitioningManager(com.facebook.presto.sql.planner.NodePartitioningManager) FINISHED(com.facebook.presto.execution.StageState.FINISHED) Session(com.facebook.presto.Session) Throwables(com.google.common.base.Throwables) LocationFactory(com.facebook.presto.execution.LocationFactory) Ints(com.google.common.primitives.Ints) MoreFutures.tryGetFutureValue(io.airlift.concurrent.MoreFutures.tryGetFutureValue) RemoteTask(com.facebook.presto.execution.RemoteTask) ConnectorId.isInternalSystemConnector(com.facebook.presto.connector.ConnectorId.isInternalSystemConnector) ABORTED(com.facebook.presto.execution.StageState.ABORTED) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) QueryState(com.facebook.presto.execution.QueryState) QueryStateMachine(com.facebook.presto.execution.QueryStateMachine) SECONDS(java.util.concurrent.TimeUnit.SECONDS) StageInfo(com.facebook.presto.execution.StageInfo)

Example 4 with StageInfo

use of com.facebook.presto.execution.StageInfo in project presto by prestodb.

the class QueryExecutionResource method getTaskInfo.

@GET
@Path("/v1/query-execution/{queryId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTaskInfo(@PathParam("queryId") String queryId) {
    QueryInfo query;
    try {
        query = manager.getQueryInfo(QueryId.valueOf(queryId));
    } catch (NoSuchElementException e) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    List<StageInfo> stages = collectStages(query.getOutputStage());
    List<Task> tasks = new ArrayList<>();
    List<Flow> flows = new ArrayList<>();
    for (StageInfo stage : stages) {
        for (TaskInfo task : stage.getTasks()) {
            int bufferedPages = 0;
            TaskStatus taskStatus = task.getTaskStatus();
            for (BufferInfo bufferInfo : task.getOutputBuffers().getBuffers()) {
                bufferedPages += bufferInfo.getBufferedPages();
                if (!bufferInfo.getBufferId().equals(OUTPUT_TASK_ID)) {
                    flows.add(new Flow(taskStatus.getTaskId().toString(), bufferInfo.getBufferId().toString(), bufferInfo.getPageBufferInfo().getPagesAdded(), bufferInfo.getBufferedPages(), bufferInfo.isFinished()));
                }
            }
            long last = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
            if (task.getStats().getEndTime() != null) {
                last = task.getStats().getEndTime().getMillis();
            }
            tasks.add(new Task(taskStatus.getTaskId().toString(), taskStatus.getState().toString(), taskStatus.getSelf().getHost(), last - task.getStats().getCreateTime().getMillis(), task.getStats().getTotalCpuTime().roundTo(TimeUnit.MILLISECONDS), task.getStats().getTotalBlockedTime().roundTo(TimeUnit.MILLISECONDS), task.getStats().getRawInputDataSize().roundTo(DataSize.Unit.BYTE), task.getStats().getRawInputPositions(), task.getStats().getOutputDataSize().roundTo(DataSize.Unit.BYTE), task.getStats().getOutputPositions(), task.getStats().getMemoryReservation().roundTo(DataSize.Unit.BYTE), task.getStats().getQueuedDrivers(), task.getStats().getRunningDrivers(), task.getStats().getCompletedDrivers(), bufferedPages));
        }
    }
    Map<String, Object> result = ImmutableMap.<String, Object>builder().put("tasks", tasks).put("flows", flows).build();
    return Response.ok(result).build();
}
Also used : BufferInfo(com.facebook.presto.execution.buffer.BufferInfo) StageInfo(com.facebook.presto.execution.StageInfo) ArrayList(java.util.ArrayList) QueryInfo(com.facebook.presto.execution.QueryInfo) TaskStatus(com.facebook.presto.execution.TaskStatus) TaskInfo(com.facebook.presto.execution.TaskInfo) NoSuchElementException(java.util.NoSuchElementException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

StageInfo (com.facebook.presto.execution.StageInfo)4 TaskInfo (com.facebook.presto.execution.TaskInfo)3 Session (com.facebook.presto.Session)2 TaskStats (com.facebook.presto.operator.TaskStats)2 ArrayList (java.util.ArrayList)2 OutputBuffers (com.facebook.presto.OutputBuffers)1 OutputBufferId (com.facebook.presto.OutputBuffers.OutputBufferId)1 ConnectorId (com.facebook.presto.connector.ConnectorId)1 ConnectorId.isInternalSystemConnector (com.facebook.presto.connector.ConnectorId.isInternalSystemConnector)1 LocationFactory (com.facebook.presto.execution.LocationFactory)1 NodeTaskMap (com.facebook.presto.execution.NodeTaskMap)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 QueryState (com.facebook.presto.execution.QueryState)1 QueryStateMachine (com.facebook.presto.execution.QueryStateMachine)1 QueryStats (com.facebook.presto.execution.QueryStats)1 RemoteTask (com.facebook.presto.execution.RemoteTask)1 RemoteTaskFactory (com.facebook.presto.execution.RemoteTaskFactory)1 SqlStageExecution (com.facebook.presto.execution.SqlStageExecution)1 StageId (com.facebook.presto.execution.StageId)1 StageInfo.getAllStages (com.facebook.presto.execution.StageInfo.getAllStages)1