Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Refactored SerenityConfig #157

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Applied refactor to other components.
Signed-off-by: bplotka <[email protected]>
  • Loading branch information
bwplotka committed Feb 17, 2016
commit df386ab21ab7b05abfbe57790f15246d577434c5
6 changes: 3 additions & 3 deletions src/contention_detectors/overload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void OverloadDetector::allProductsReady() {

if (totalAgentCpus.isNone()) {
SERENITY_LOG(ERROR) << std::string(NAME)
<< " No total cpus in ResourceUsage";
<< " No total cpus in ResourceUsage";
produce(product);
}

Expand All @@ -34,7 +34,7 @@ void OverloadDetector::allProductsReady() {

for (const ResourceUsage_Executor& inExec : usage.executors()) {
// Validate for statistics and executor info.
if (!validate(inExec)) {
if (!hasRequiredFields(inExec)) {
continue;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ void OverloadDetector::allProductsReady() {
produce(product);
}

bool OverloadDetector::validate(const ResourceUsage_Executor& inExec) {
bool OverloadDetector::hasRequiredFields(const ResourceUsage_Executor& inExec) {
if (!inExec.has_executor_info()) {
SERENITY_LOG(ERROR) << "Executor <unknown>"
<< " does not include executor_info";
Expand Down
2 changes: 1 addition & 1 deletion src/contention_detectors/overload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class OverloadDetector :

protected:
void allProductsReady() override;
bool validate(const ResourceUsage_Executor& inExec);
bool hasRequiredFields(const ResourceUsage_Executor& inExec);

const Tag tag;
const lambda::function<usage::GetterFunction> cpuUsageGetFunction;
Expand Down
32 changes: 9 additions & 23 deletions src/filters/too_low_usage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@
namespace mesos {
namespace serenity {

class TooLowUsageFilterConfig : public SerenityConfig {
public:
TooLowUsageFilterConfig() { }

explicit TooLowUsageFilterConfig(const SerenityConfig& customCfg) {
this->initDefaults();
this->applyConfig(customCfg);
}

void initDefaults() {
//! double_t
//! Minimal cpu usage
this->items[too_low_usage::MINIMAL_CPU_USAGE] =
too_low_usage::DEFAULT_MINIMAL_CPU_USAGE;
}
};


/**
* Filter out PR executors with too low metrics.
* Currently we filter out when CPU Usage is below specified threshold.
Expand All @@ -44,12 +26,12 @@ class TooLowUsageFilter :

explicit TooLowUsageFilter(
Consumer<ResourceUsage>* _consumer,
SerenityConfig _conf,
const SerenityConfig& _conf,
const Tag& _tag = Tag(QOS_CONTROLLER, NAME))
: Producer<ResourceUsage>(_consumer), tag(_tag) {
SerenityConfig config = TooLowUsageFilterConfig(_conf);
this->cfgMinimalCpuUsage =
config.item<double_t>(too_low_usage::MINIMAL_CPU_USAGE).get();
setCfgMinimalCpuUsage(_conf.item<double_t>(
too_low_usage::MINIMAL_CPU_USAGE,
too_low_usage::DEFAULT_MINIMAL_CPU_USAGE));
}

~TooLowUsageFilter();
Expand All @@ -58,7 +40,11 @@ class TooLowUsageFilter :

Try<Nothing> consume(const ResourceUsage& in);

public:
void setCfgMinimalCpuUsage(double_t cfgMinimalCpuUsage) {
TooLowUsageFilter::cfgMinimalCpuUsage = cfgMinimalCpuUsage;
}

protected:
const Tag tag;

double_t cfgMinimalCpuUsage;
Expand Down
33 changes: 7 additions & 26 deletions src/observers/strategies/cpu_contention.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,6 @@
namespace mesos {
namespace serenity {

class CpuContentionStrategyConfig : public SerenityConfig {
public:
CpuContentionStrategyConfig() {
this->initDefaults();
}

explicit CpuContentionStrategyConfig(const SerenityConfig& customCfg) {
this->initDefaults();
this->applyConfig(customCfg);
}

void initDefaults() {
// uint64_t
// Specify the initial value of iterations we should wait until
// we create new correction.
this->items[strategy::CONTENTION_COOLDOWN] =
strategy::DEFAULT_CONTENTION_COOLDOWN;
// double_t
this->items[strategy::DEFAULT_CPU_SEVERITY] =
strategy::DEFAULT_DEFAULT_CPU_SEVERITY;
}
};


/**
* Checks contentions and choose executors to kill.
* It accepts only Contention_Type_CPU.
Expand All @@ -51,7 +27,9 @@ class CpuContentionStrategy : public RevocationStrategy {
const lambda::function<usage::GetterFunction>& _cpuUsageGetFunction)
: RevocationStrategy(Tag(QOS_CONTROLLER, "CpuContentionStrategy")),
getCpuUsage(_cpuUsageGetFunction) {
SerenityConfig config = CpuContentionStrategyConfig(_config);
setDefaultSeverity(_config.item<double_t>(
strategy::DEFAULT_CPU_SEVERITY,
strategy::DEFAULT_DEFAULT_CPU_SEVERITY));
}

Try<QoSCorrections> decide(ExecutorAgeFilter* ageFilter,
Expand All @@ -60,11 +38,14 @@ class CpuContentionStrategy : public RevocationStrategy {

static const constexpr char* NAME = "CpuContentionStrategy";

void setDefaultSeverity(double_t defaultSeverity) {
CpuContentionStrategy::defaultSeverity = defaultSeverity;
}

private:
const lambda::function<usage::GetterFunction> getCpuUsage;

// cfg parameters.
uint64_t cooldownTime;
double_t defaultSeverity;
};

Expand Down