예제 #1
0
Try<Nothing> PrExecutorPassFilter::consume(const ResourceUsage& in) {
  ResourceUsage product;
  product.mutable_total()->CopyFrom(in.total());
  for (ResourceUsage_Executor inExec : in.executors()) {
    if (!inExec.has_executor_info()) {
      LOG(ERROR) << name << "Executor <unknown>"
                 << " does not include executor_info";
      // Filter out these executors.
      continue;
    }
    if (inExec.allocated().size() == 0) {
      LOG(ERROR) << name << "Executor "
      << inExec.executor_info().executor_id().value()
      << " does not include allocated resources.";
      // Filter out these executors.
      continue;
    }

    Resources allocated(inExec.allocated());
    // Check if task uses revocable resources.
    if (!allocated.revocable().empty()) {
      continue;
    }

    // Add an PR executor.
    ResourceUsage_Executor* outExec = product.mutable_executors()->Add();
    outExec->CopyFrom(inExec);
  }

  produce(product);

  return Nothing();
}
예제 #2
0
Try<Nothing> TooHighCpuUsageDetector::consume(const ResourceUsage& in) {
  Contentions product;

  if (in.total_size() == 0) {
    return Error(std::string(NAME) + " No total in ResourceUsage");
  }

  Resources totalAgentResources(in.total());
  Option<double_t> totalAgentCpus = totalAgentResources.cpus();

  if (totalAgentCpus.isNone()) {
    return Error(std::string(NAME) + " No total cpus in ResourceUsage");
  }

  double_t agentSumValue = 0;
  uint64_t beExecutors = 0;

  for (const ResourceUsage_Executor& inExec : in.executors()) {
    if (!inExec.has_executor_info()) {
      SERENITY_LOG(ERROR) << "Executor <unknown>"
      << " does not include executor_info";
      // Filter out these executors.
      continue;
    }
    if (!inExec.has_statistics()) {
      SERENITY_LOG(ERROR) << "Executor "
      << inExec.executor_info().executor_id().value()
      << " does not include statistics.";
      // Filter out these executors.
      continue;
    }

    Try<double_t> value = this->cpuUsageGetFunction(inExec);
    if (value.isError()) {
      SERENITY_LOG(ERROR) << value.error();
      continue;
    }

    agentSumValue += value.get();

    if (!Resources(inExec.allocated()).revocable().empty()) {
      beExecutors++;
    }
  }

  // Debug only
  SERENITY_LOG(INFO) << "Sum = " << agentSumValue << " vs total = "
                     << totalAgentCpus.get();
  double_t lvl = agentSumValue / totalAgentCpus.get();

  if (lvl > this->cfgUtilizationThreshold) {
    if (beExecutors == 0) {
      SERENITY_LOG(INFO) << "No BE tasks - only high host utilization";
    } else {
      SERENITY_LOG(INFO) << "Creating CPU contention, because of the value"
                         << " above the threshold. " << agentSumValue << "/"
                         << totalAgentCpus.get();
      product.push_back(createContention(totalAgentCpus.get() - agentSumValue,
                                         Contention_Type_CPU));
    }
  }

  // Continue pipeline.
  this->produce(product);

  return Nothing();
}
예제 #3
0
파일: ema.cpp 프로젝트: Bplotka/serenity
Try<Nothing> EMAFilter::consume(const ResourceUsage& in) {
  ResourceUsage product;

  for (ResourceUsage_Executor inExec : in.executors()) {
    if (!inExec.has_executor_info()) {
      SERENITY_LOG(ERROR) << "Executor <unknown>"
                 << " does not include executor_info";
      // Filter out these executors.
      continue;
    }
    if (!inExec.has_statistics()) {
      SERENITY_LOG(ERROR) << "Executor "
                 << inExec.executor_info().executor_id().value()
                 << " does not include statistics.";
      // Filter out these executors.
      continue;
    }

    // Check if EMA for given executor exists.
    auto emaSample = this->emaSamples->find(inExec.executor_info());
    if (emaSample == this->emaSamples->end()) {
      SERENITY_LOG(ERROR) << "First EMA iteration for: "
                          << WID(inExec.executor_info()).toString();
      // If not - insert new one.
      ExponentialMovingAverage ema(EMA_REGULAR_SERIES, this->alpha);
      emaSamples->insert(std::pair<ExecutorInfo, ExponentialMovingAverage>(
          inExec.executor_info(), ema));

    } else {
      // Get proper value.
      Try<double_t> value = this->valueGetFunction(inExec);
      if (value.isError()) {
        SERENITY_LOG(ERROR) << value.error();
        continue;
      }

      // Perform EMA filtering.
      double_t emaValue =
        (emaSample->second).calculateEMA(
            value.get(),
            inExec.statistics().perf().timestamp());

      // Store EMA value.
      ResourceUsage_Executor* outExec = new ResourceUsage_Executor(inExec);
      Try<Nothing> result = this->valueSetFunction(emaValue, outExec);
      if (result.isError()) {
        SERENITY_LOG(ERROR) << result.error();
        delete outExec;
        continue;
      }

      // Add an executor only when there was no error.
      product.mutable_executors()->AddAllocated(outExec);
    }
  }

  if (0 != product.executors_size()) {
    SERENITY_LOG(INFO) << "Continuing with "
                       << product.executors_size() << " executor(s).";
    // Continue pipeline.
    // Copy total agent's capacity.
    product.mutable_total()->CopyFrom(in.total());
    produce(product);
  }

  return Nothing();
}