コード例 #1
0
ファイル: PipelineContext.java プロジェクト: vbajaria/presto
  public void driverFinished(DriverContext driverContext) {
    checkNotNull(driverContext, "driverContext is null");

    if (!drivers.remove(driverContext)) {
      throw new IllegalArgumentException("Unknown driver " + driverContext);
    }

    DriverStats driverStats = driverContext.getDriverStats();

    completedDrivers.getAndIncrement();

    // remove the memory reservation
    memoryReservation.getAndAdd(-driverStats.getMemoryReservation().toBytes());

    queuedTime.add(driverStats.getQueuedTime().roundTo(NANOSECONDS));
    elapsedTime.add(driverStats.getElapsedTime().roundTo(NANOSECONDS));

    totalScheduledTime.getAndAdd(driverStats.getTotalScheduledTime().roundTo(NANOSECONDS));
    totalCpuTime.getAndAdd(driverStats.getTotalCpuTime().roundTo(NANOSECONDS));
    totalUserTime.getAndAdd(driverStats.getTotalUserTime().roundTo(NANOSECONDS));

    totalBlockedTime.getAndAdd(driverStats.getTotalBlockedTime().roundTo(NANOSECONDS));

    // merge the operator stats into the operator summary
    List<OperatorStats> operators = driverStats.getOperatorStats();
    for (OperatorStats operator : operators) {
      // TODO: replace with ConcurrentMap.compute() when we migrate to java 8
      OperatorStats updated;
      OperatorStats current;
      do {
        current = operatorSummaries.get(operator.getOperatorId());
        if (current != null) {
          updated = current.add(operator);
        } else {
          updated = operator;
        }
      } while (!compareAndSet(operatorSummaries, operator.getOperatorId(), current, updated));
    }

    rawInputDataSize.update(driverStats.getRawInputDataSize().toBytes());
    rawInputPositions.update(driverStats.getRawInputPositions());

    processedInputDataSize.update(driverStats.getProcessedInputDataSize().toBytes());
    processedInputPositions.update(driverStats.getProcessedInputPositions());

    outputDataSize.update(driverStats.getOutputDataSize().toBytes());
    outputPositions.update(driverStats.getOutputPositions());
  }
コード例 #2
0
ファイル: PipelineContext.java プロジェクト: vbajaria/presto
  public PipelineStats getPipelineStats() {
    List<DriverContext> driverContexts = ImmutableList.copyOf(this.drivers);

    int totalDriers = completedDrivers.get() + driverContexts.size();
    int queuedDrivers = 0;
    int runningDrivers = 0;
    int completedDrivers = this.completedDrivers.get();

    Distribution queuedTime = new Distribution(this.queuedTime);
    Distribution elapsedTime = new Distribution(this.elapsedTime);

    long totalScheduledTime = this.totalScheduledTime.get();
    long totalCpuTime = this.totalCpuTime.get();
    long totalUserTime = this.totalUserTime.get();
    long totalBlockedTime = this.totalBlockedTime.get();

    long rawInputDataSize = this.rawInputDataSize.getTotalCount();
    long rawInputPositions = this.rawInputPositions.getTotalCount();

    long processedInputDataSize = this.processedInputDataSize.getTotalCount();
    long processedInputPositions = this.processedInputPositions.getTotalCount();

    long outputDataSize = this.outputDataSize.getTotalCount();
    long outputPositions = this.outputPositions.getTotalCount();

    List<DriverStats> drivers = new ArrayList<>();

    Multimap<Integer, OperatorStats> runningOperators = ArrayListMultimap.create();
    for (DriverContext driverContext : driverContexts) {
      DriverStats driverStats = driverContext.getDriverStats();
      drivers.add(driverStats);

      if (driverStats.getStartTime() == null) {
        queuedDrivers++;
      } else {
        runningDrivers++;
      }

      queuedTime.add(driverStats.getQueuedTime().roundTo(NANOSECONDS));
      elapsedTime.add(driverStats.getElapsedTime().roundTo(NANOSECONDS));

      totalScheduledTime += driverStats.getTotalScheduledTime().roundTo(NANOSECONDS);
      totalCpuTime += driverStats.getTotalCpuTime().roundTo(NANOSECONDS);
      totalUserTime += driverStats.getTotalUserTime().roundTo(NANOSECONDS);
      totalBlockedTime += driverStats.getTotalBlockedTime().roundTo(NANOSECONDS);

      List<OperatorStats> operators =
          ImmutableList.copyOf(
              transform(driverContext.getOperatorContexts(), operatorStatsGetter()));
      for (OperatorStats operator : operators) {
        runningOperators.put(operator.getOperatorId(), operator);
      }

      rawInputDataSize += driverStats.getRawInputDataSize().toBytes();
      rawInputPositions += driverStats.getRawInputPositions();

      processedInputDataSize += driverStats.getProcessedInputDataSize().toBytes();
      processedInputPositions += driverStats.getProcessedInputPositions();

      outputDataSize += driverStats.getOutputDataSize().toBytes();
      outputPositions += driverStats.getOutputPositions();
    }

    // merge the operator stats into the operator summary
    TreeMap<Integer, OperatorStats> operatorSummaries = new TreeMap<>();
    for (Entry<Integer, OperatorStats> entry : this.operatorSummaries.entrySet()) {
      OperatorStats operator = entry.getValue();
      operator.add(runningOperators.get(entry.getKey()));
      operatorSummaries.put(entry.getKey(), operator);
    }

    return new PipelineStats(
        inputPipeline,
        outputPipeline,
        totalDriers,
        queuedDrivers,
        runningDrivers,
        completedDrivers,
        new DataSize(memoryReservation.get(), BYTE).convertToMostSuccinctDataSize(),
        queuedTime.snapshot(),
        elapsedTime.snapshot(),
        new Duration(totalScheduledTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
        new Duration(totalCpuTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
        new Duration(totalUserTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
        new Duration(totalBlockedTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
        new DataSize(rawInputDataSize, BYTE).convertToMostSuccinctDataSize(),
        rawInputPositions,
        new DataSize(processedInputDataSize, BYTE).convertToMostSuccinctDataSize(),
        processedInputPositions,
        new DataSize(outputDataSize, BYTE).convertToMostSuccinctDataSize(),
        outputPositions,
        ImmutableList.copyOf(operatorSummaries.values()),
        drivers);
  }