Search in sources :

Example 11 with TaskStats

use of com.facebook.presto.operator.TaskStats in project urban-eureka by errir503.

the class AbstractOperatorBenchmark method runOnce.

@Override
protected Map<String, Long> runOnce() {
    Session session = testSessionBuilder().setSystemProperty("optimizer.optimize-hash-generation", "true").build();
    MemoryPool memoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(1, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(new DataSize(1, GIGABYTE));
    TaskContext taskContext = new QueryContext(new QueryId("test"), new DataSize(256, MEGABYTE), new DataSize(512, MEGABYTE), new DataSize(256, MEGABYTE), new DataSize(1, GIGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(256, MEGABYTE), spillSpaceTracker, listJsonCodec(TaskMemoryReservationSummary.class)).addTaskContext(new TaskStateMachine(new TaskId("query", 0, 0, 0), localQueryRunner.getExecutor()), session, Optional.empty(), false, false, false, false, false);
    CpuTimer cpuTimer = new CpuTimer();
    Map<String, Long> executionStats = execute(taskContext);
    CpuDuration executionTime = cpuTimer.elapsedTime();
    TaskStats taskStats = taskContext.getTaskStats();
    long inputRows = taskStats.getRawInputPositions();
    long inputBytes = taskStats.getRawInputDataSizeInBytes();
    long outputRows = taskStats.getOutputPositions();
    long outputBytes = taskStats.getOutputDataSizeInBytes();
    double inputMegaBytes = new DataSize(inputBytes, BYTE).getValue(MEGABYTE);
    return ImmutableMap.<String, Long>builder().putAll(executionStats).put("elapsed_millis", executionTime.getWall().toMillis()).put("input_rows_per_second", (long) (inputRows / executionTime.getWall().getValue(SECONDS))).put("output_rows_per_second", (long) (outputRows / executionTime.getWall().getValue(SECONDS))).put("input_megabytes", (long) inputMegaBytes).put("input_megabytes_per_second", (long) (inputMegaBytes / executionTime.getWall().getValue(SECONDS))).put("wall_nanos", executionTime.getWall().roundTo(NANOSECONDS)).put("cpu_nanos", executionTime.getCpu().roundTo(NANOSECONDS)).put("user_nanos", executionTime.getUser().roundTo(NANOSECONDS)).put("input_rows", inputRows).put("input_bytes", inputBytes).put("output_rows", outputRows).put("output_bytes", outputBytes).build();
}
Also used : SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) TaskContext(com.facebook.presto.operator.TaskContext) TaskId(com.facebook.presto.execution.TaskId) QueryId(com.facebook.presto.spi.QueryId) QueryContext(com.facebook.presto.memory.QueryContext) TaskStats(com.facebook.presto.operator.TaskStats) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) DataSize(io.airlift.units.DataSize) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) CpuTimer(com.facebook.airlift.stats.CpuTimer) CpuDuration(com.facebook.airlift.stats.CpuTimer.CpuDuration) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) Session(com.facebook.presto.Session) MemoryPool(com.facebook.presto.memory.MemoryPool)

Example 12 with TaskStats

use of com.facebook.presto.operator.TaskStats in project urban-eureka by errir503.

the class TaskSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(TASK_TABLE);
    for (TaskInfo taskInfo : taskManager.getAllTaskInfo()) {
        TaskStats stats = taskInfo.getStats();
        TaskStatus taskStatus = taskInfo.getTaskStatus();
        table.addRow(nodeId, taskInfo.getTaskId().toString(), taskInfo.getTaskId().getStageExecutionId().toString(), taskInfo.getTaskId().getStageExecutionId().getStageId().toString(), taskInfo.getTaskId().getQueryId().toString(), taskStatus.getState().toString(), (long) stats.getTotalDrivers(), (long) stats.getQueuedDrivers(), (long) stats.getRunningDrivers(), (long) stats.getCompletedDrivers(), NANOSECONDS.toMillis(stats.getTotalScheduledTimeInNanos()), NANOSECONDS.toMillis(stats.getTotalCpuTimeInNanos()), NANOSECONDS.toMillis(stats.getTotalBlockedTimeInNanos()), stats.getRawInputDataSizeInBytes(), stats.getRawInputPositions(), stats.getProcessedInputDataSizeInBytes(), stats.getProcessedInputPositions(), stats.getOutputDataSizeInBytes(), stats.getOutputPositions(), stats.getPhysicalWrittenDataSizeInBytes(), toTimeStamp(stats.getCreateTime()), toTimeStamp(stats.getFirstStartTime()), toTimeStamp(taskInfo.getLastHeartbeat()), toTimeStamp(stats.getEndTime()));
    }
    return table.build().cursor();
}
Also used : TaskInfo(com.facebook.presto.execution.TaskInfo) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) TaskStats(com.facebook.presto.operator.TaskStats) TaskStatus(com.facebook.presto.execution.TaskStatus)

Example 13 with TaskStats

use of com.facebook.presto.operator.TaskStats in project urban-eureka by errir503.

the class GcStatusMonitor method logTaskStats.

private static void logTaskStats(List<QueryId> queryIds, ListMultimap<QueryId, SqlTask> tasksByQueryId) {
    List<List<String>> rows = queryIds.stream().flatMap(queryId -> {
        List<SqlTask> sqlTasks = tasksByQueryId.get(queryId);
        Comparator<SqlTask> comparator = (first, second) -> {
            TaskStats aTaskStats = first.getTaskInfo().getStats();
            TaskStats bTaskStats = second.getTaskInfo().getStats();
            return Long.compare(aTaskStats.getUserMemoryReservationInBytes() + aTaskStats.getSystemMemoryReservationInBytes(), bTaskStats.getUserMemoryReservationInBytes() + bTaskStats.getSystemMemoryReservationInBytes());
        };
        return sqlTasks.stream().sorted(comparator.reversed()).map(task -> {
            TaskInfo taskInfo = task.getTaskInfo();
            SqlTaskIoStats taskIOStats = task.getIoStats();
            TaskStatus taskStatus = taskInfo.getTaskStatus();
            TaskStats taskStats = taskInfo.getStats();
            return ImmutableList.of(task.getQueryContext().getQueryId().toString(), task.getTaskId().toString(), taskStatus.getState().toString(), taskStats.getCreateTime().toString(), Long.toString(taskStats.getUserMemoryReservationInBytes()), Long.toString(taskStats.getSystemMemoryReservationInBytes()), Long.toString(taskIOStats.getInputDataSize().getTotalCount()), Long.toString(taskIOStats.getOutputDataSize().getTotalCount()), Long.toString(taskIOStats.getInputPositions().getTotalCount()), Long.toString(taskIOStats.getOutputPositions().getTotalCount()));
        });
    }).collect(toImmutableList());
    if (!rows.isEmpty()) {
        logInfoTable(ImmutableList.<List<String>>builder().add(ImmutableList.of("Query ID", "Task ID", "State", "Created Ts", "User Memory", "System Memory", "Input Bytes", "Output Bytes", "Input Row Count", "Output Row Count")).addAll(rows).build());
    }
}
Also used : TaskStats(com.facebook.presto.operator.TaskStats) NotificationListener(javax.management.NotificationListener) Logger(com.facebook.airlift.log.Logger) ListMultimap(com.google.common.collect.ListMultimap) TaskStatus(com.facebook.presto.execution.TaskStatus) Function(java.util.function.Function) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) ImmutableListMultimap.toImmutableListMultimap(com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap) SqlTaskManager(com.facebook.presto.execution.SqlTaskManager) ImmutableList(com.google.common.collect.ImmutableList) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) Objects.requireNonNull(java.util.Objects.requireNonNull) SqlTask(com.facebook.presto.execution.SqlTask) GarbageCollectionNotificationInfo(com.facebook.airlift.stats.GarbageCollectionNotificationInfo) ManagementFactory(java.lang.management.ManagementFactory) SimpleEntry(java.util.AbstractMap.SimpleEntry) StringTableUtils.getTableStrings(com.facebook.presto.util.StringTableUtils.getTableStrings) SqlTaskIoStats(com.facebook.presto.execution.SqlTaskIoStats) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CompositeData(javax.management.openmbean.CompositeData) ObjectName(javax.management.ObjectName) Notification(javax.management.Notification) List(java.util.List) JMException(javax.management.JMException) QueryId(com.facebook.presto.spi.QueryId) PostConstruct(javax.annotation.PostConstruct) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) TaskInfo(com.facebook.presto.execution.TaskInfo) TaskInfo(com.facebook.presto.execution.TaskInfo) SqlTaskIoStats(com.facebook.presto.execution.SqlTaskIoStats) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) TaskStats(com.facebook.presto.operator.TaskStats) TaskStatus(com.facebook.presto.execution.TaskStatus) Comparator(java.util.Comparator)

Example 14 with TaskStats

use of com.facebook.presto.operator.TaskStats in project presto by prestodb.

the class StageStateMachine method getStageInfo.

public StageInfo getStageInfo(Supplier<Iterable<TaskInfo>> taskInfosSupplier, Supplier<Iterable<StageInfo>> subStageInfosSupplier) {
    // stage state must be captured first in order to provide a
    // consistent view of the stage. For example, building this
    // information, the stage could finish, and the task states would
    // never be visible.
    StageState state = stageState.get();
    List<TaskInfo> taskInfos = ImmutableList.copyOf(taskInfosSupplier.get());
    List<StageInfo> subStageInfos = ImmutableList.copyOf(subStageInfosSupplier.get());
    int totalTasks = taskInfos.size();
    int runningTasks = 0;
    int completedTasks = 0;
    int totalDrivers = 0;
    int queuedDrivers = 0;
    int runningDrivers = 0;
    int completedDrivers = 0;
    long cumulativeMemory = 0;
    long totalMemoryReservation = 0;
    long peakMemoryReservation = getPeakMemoryInBytes();
    long totalScheduledTime = 0;
    long totalCpuTime = 0;
    long totalUserTime = 0;
    long totalBlockedTime = 0;
    long rawInputDataSize = 0;
    long rawInputPositions = 0;
    long processedInputDataSize = 0;
    long processedInputPositions = 0;
    long outputDataSize = 0;
    long outputPositions = 0;
    boolean fullyBlocked = true;
    Set<BlockedReason> blockedReasons = new HashSet<>();
    Map<String, OperatorStats> operatorToStats = new HashMap<>();
    for (TaskInfo taskInfo : taskInfos) {
        TaskState taskState = taskInfo.getTaskStatus().getState();
        if (taskState.isDone()) {
            completedTasks++;
        } else {
            runningTasks++;
        }
        TaskStats taskStats = taskInfo.getStats();
        totalDrivers += taskStats.getTotalDrivers();
        queuedDrivers += taskStats.getQueuedDrivers();
        runningDrivers += taskStats.getRunningDrivers();
        completedDrivers += taskStats.getCompletedDrivers();
        cumulativeMemory += taskStats.getCumulativeMemory();
        totalMemoryReservation += taskStats.getMemoryReservation().toBytes();
        totalScheduledTime += taskStats.getTotalScheduledTime().roundTo(NANOSECONDS);
        totalCpuTime += taskStats.getTotalCpuTime().roundTo(NANOSECONDS);
        totalUserTime += taskStats.getTotalUserTime().roundTo(NANOSECONDS);
        totalBlockedTime += taskStats.getTotalBlockedTime().roundTo(NANOSECONDS);
        if (!taskState.isDone()) {
            fullyBlocked &= taskStats.isFullyBlocked();
            blockedReasons.addAll(taskStats.getBlockedReasons());
        }
        rawInputDataSize += taskStats.getRawInputDataSize().toBytes();
        rawInputPositions += taskStats.getRawInputPositions();
        processedInputDataSize += taskStats.getProcessedInputDataSize().toBytes();
        processedInputPositions += taskStats.getProcessedInputPositions();
        outputDataSize += taskStats.getOutputDataSize().toBytes();
        outputPositions += taskStats.getOutputPositions();
        for (PipelineStats pipeline : taskStats.getPipelines()) {
            for (OperatorStats operatorStats : pipeline.getOperatorSummaries()) {
                String id = pipeline.getPipelineId() + "." + operatorStats.getOperatorId();
                operatorToStats.compute(id, (k, v) -> v == null ? operatorStats : v.add(operatorStats));
            }
        }
    }
    StageStats stageStats = new StageStats(schedulingComplete.get(), getSplitDistribution.snapshot(), scheduleTaskDistribution.snapshot(), addSplitDistribution.snapshot(), totalTasks, runningTasks, completedTasks, totalDrivers, queuedDrivers, runningDrivers, completedDrivers, cumulativeMemory, succinctBytes(totalMemoryReservation), succinctBytes(peakMemoryReservation), succinctDuration(totalScheduledTime, NANOSECONDS), succinctDuration(totalCpuTime, NANOSECONDS), succinctDuration(totalUserTime, NANOSECONDS), succinctDuration(totalBlockedTime, NANOSECONDS), fullyBlocked && runningTasks > 0, blockedReasons, succinctBytes(rawInputDataSize), rawInputPositions, succinctBytes(processedInputDataSize), processedInputPositions, succinctBytes(outputDataSize), outputPositions, ImmutableList.copyOf(operatorToStats.values()));
    ExecutionFailureInfo failureInfo = null;
    if (state == FAILED) {
        failureInfo = failureCause.get();
    }
    return new StageInfo(stageId, state, location, fragment, fragment.getTypes(), stageStats, taskInfos, subStageInfos, failureInfo);
}
Also used : PipelineStats(com.facebook.presto.operator.PipelineStats) BlockedReason(com.facebook.presto.operator.BlockedReason) HashMap(java.util.HashMap) OperatorStats(com.facebook.presto.operator.OperatorStats) TaskStats(com.facebook.presto.operator.TaskStats) HashSet(java.util.HashSet)

Example 15 with TaskStats

use of com.facebook.presto.operator.TaskStats in project urban-eureka by errir503.

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().toMillis();
        List<StageInfo> stages = 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.getLatestAttemptExecutionInfo().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 = max(queryEndTime.getMillis() - queryStartTime.getMillis(), 0);
        long scheduling = max(firstTaskStartTime - queryStartTime.getMillis() - planning, 0);
        long running = max(lastTaskEndTime - firstTaskStartTime, 0);
        long finishing = max(queryEndTime.getMillis() - lastTaskEndTime, 0);
        logQueryTimeline(queryInfo.getQueryId(), queryInfo.getSession().getTransactionId().map(TransactionId::toString).orElse(""), elapsed, planning, scheduling, running, finishing, 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) TransactionId(com.facebook.presto.transaction.TransactionId)

Aggregations

TaskStats (com.facebook.presto.operator.TaskStats)21 TaskInfo (com.facebook.presto.execution.TaskInfo)8 HashSet (java.util.HashSet)6 BlockedReason (com.facebook.presto.operator.BlockedReason)5 DateTime (org.joda.time.DateTime)5 StageInfo (com.facebook.presto.execution.StageInfo)4 TaskStatus (com.facebook.presto.execution.TaskStatus)4 OperatorStats (com.facebook.presto.operator.OperatorStats)4 PipelineStats (com.facebook.presto.operator.PipelineStats)4 TaskContext (com.facebook.presto.operator.TaskContext)4 QueryId (com.facebook.presto.spi.QueryId)4 HashMap (java.util.HashMap)4 Session (com.facebook.presto.Session)3 QueryStats (com.facebook.presto.execution.QueryStats)3 ImmutableList (com.google.common.collect.ImmutableList)3 Logger (com.facebook.airlift.log.Logger)2 CpuTimer (com.facebook.airlift.stats.CpuTimer)2 CpuDuration (com.facebook.airlift.stats.CpuTimer.CpuDuration)2 GarbageCollectionNotificationInfo (com.facebook.airlift.stats.GarbageCollectionNotificationInfo)2 TestingGcMonitor (com.facebook.airlift.stats.TestingGcMonitor)2