-
Notifications
You must be signed in to change notification settings - Fork 19
Refactored SerenityConfig #157
base: master
Are you sure you want to change the base?
Changes from 5 commits
550d4ce
f19fd5f
fde11f8
3e297af
df386ab
1a7e32a
e48e3d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,22 +20,6 @@ | |
| namespace mesos { | ||
| namespace serenity { | ||
|
|
||
| class OverloadDetectorConfig : public SerenityConfig { | ||
| public: | ||
| OverloadDetectorConfig() { } | ||
|
|
||
| explicit OverloadDetectorConfig(const SerenityConfig& customCfg) { | ||
| this->initDefaults(); | ||
| this->applyConfig(customCfg); | ||
| } | ||
|
|
||
| void initDefaults() { | ||
| //! double_t | ||
| //! Detector threshold. | ||
| this->fields[detector::THRESHOLD] = | ||
| detector::DEFAULT_UTILIZATION_THRESHOLD; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * OverloadDetector is able to create contention if utilization is above | ||
|
|
@@ -48,23 +32,29 @@ class OverloadDetector : | |
| OverloadDetector( | ||
| Consumer<Contentions>* _consumer, | ||
| const lambda::function<usage::GetterFunction>& _cpuUsageGetFunction, | ||
| SerenityConfig _conf, | ||
| const SerenityConfig& _conf, | ||
| const Tag& _tag = Tag(QOS_CONTROLLER, NAME)) | ||
| : tag(_tag), | ||
| cpuUsageGetFunction(_cpuUsageGetFunction), | ||
| Producer<Contentions>(_consumer) { | ||
| SerenityConfig config = OverloadDetectorConfig(_conf); | ||
| this->cfgUtilizationThreshold = | ||
| config.getD(detector::THRESHOLD); | ||
| // Parse config values. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is rather self-explanatory. |
||
| setCfgUtilizationThreshold( | ||
| _conf.item<double_t>(detector::THRESHOLD, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| detector::DEFAULT_UTILIZATION_THRESHOLD)); | ||
| } | ||
|
|
||
| ~OverloadDetector() {} | ||
|
|
||
| Try<Nothing> consume(const ResourceUsage& in) override; | ||
|
|
||
| static const constexpr char* NAME = "OverloadDetector"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Field should be below functions, right? |
||
|
|
||
| void setCfgUtilizationThreshold(double_t cfgUtilizationThreshold) { | ||
| OverloadDetector::cfgUtilizationThreshold = cfgUtilizationThreshold; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /s/cfgUtilizationThreshold/utilizationThreshold |
||
| } | ||
|
|
||
| protected: | ||
| void allProductsReady() override; | ||
| bool hasRequiredFields(const ResourceUsage_Executor& inExec); | ||
|
|
||
| const Tag tag; | ||
| const lambda::function<usage::GetterFunction> cpuUsageGetFunction; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,56 +30,6 @@ namespace serenity { | |
|
|
||
| #define SIGNAL_DROP_ANALYZER_NAME "AssuranceDropAnalyzer" | ||
|
|
||
| class SignalDropAnalyzerConfig : public SerenityConfig { | ||
| public: | ||
| SignalDropAnalyzerConfig() {} | ||
|
|
||
| explicit SignalDropAnalyzerConfig(const SerenityConfig& customCfg) { | ||
| this->initDefaults(); | ||
| this->applyConfig(customCfg); | ||
| } | ||
|
|
||
| void initDefaults() { | ||
| this->fields[detector::ANALYZER_TYPE] = SIGNAL_DROP_ANALYZER_NAME; | ||
| //! uint64_t | ||
| //! How far in the past we look. | ||
| this->fields[detector::WINDOW_SIZE] = | ||
| detector::DEFAULT_WINDOW_SIZE; | ||
|
|
||
| //! double_t | ||
| //! Defines how much (relatively to base point) value must drop to trigger | ||
| //! contention. | ||
| //! Most signal_analyzer will use that. | ||
| this->fields[detector::FRACTIONAL_THRESHOLD] = | ||
| detector::DEFAULT_FRACTIONAL_THRESHOLD; | ||
|
|
||
| //! double_t | ||
| //! You can adjust how big severity is created for a defined drop. | ||
| //! if -1 then unknown severity will be reported. | ||
| this->fields[detector::SEVERITY_FRACTION] = (double_t) -1; | ||
|
|
||
| //! double_t | ||
| //! Tolerance fraction of threshold if signal is accepted as returned to | ||
| //! previous state after drop. | ||
| this->fields[detector::NEAR_FRACTION] = | ||
| detector::DEFAULT_NEAR_FRACTION; | ||
|
|
||
| //! uint64_t | ||
| //! Maximum number of checkpoints we will have in our assurance detector. | ||
| //! Checkpoints are the reference assurance_test(base) points which we refer | ||
| //! to in the past when detecting drop or not. | ||
| //! It needs to be 0 < < WINDOW_SIZE | ||
| this->fields[detector::MAX_CHECKPOINTS] = | ||
| detector::DEFAULT_MAX_CHECKPOINTS; | ||
|
|
||
| //! double_t | ||
| //! Fraction of checkpoints' votes that important decision needs to obtain. | ||
| this->fields[detector::QUORUM] = | ||
| detector::DEFAULT_QUORUM; | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * Dynamic implementation of sequential change point detection. | ||
| * | ||
|
|
@@ -109,13 +59,29 @@ class SignalDropAnalyzer : public SignalAnalyzer { | |
| : SignalAnalyzer(_tag), | ||
| valueBeforeDrop(None()), | ||
| quorumNum(0) { | ||
| SerenityConfig config = SignalDropAnalyzerConfig(_config); | ||
| this->cfgWindowSize = config.getU64(detector::WINDOW_SIZE); | ||
| this->cfgMaxCheckpoints = config.getU64(detector::MAX_CHECKPOINTS); | ||
| this->cfgQuroum = config.getD(detector::QUORUM); | ||
| this->cfgFractionalThreshold = config.getD(detector::FRACTIONAL_THRESHOLD); | ||
| this->cfgNearFraction = config.getD(detector::NEAR_FRACTION); | ||
| this->cfgSeverityFraction = config.getD(detector::SEVERITY_FRACTION); | ||
| setCfgWindowSize(_config.item<int64_t>( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove all cfg prefixes |
||
| detector::WINDOW_SIZE, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please start to move all statics to proper classes. |
||
| detector::DEFAULT_WINDOW_SIZE)); | ||
|
|
||
| setCfgMaxCheckpoints(_config.item<int64_t>( | ||
| detector::MAX_CHECKPOINTS, | ||
| detector::DEFAULT_MAX_CHECKPOINTS)); | ||
|
|
||
| setCfgQuroum(_config.item<double_t>( | ||
| detector::QUORUM, | ||
| detector::DEFAULT_QUORUM)); | ||
|
|
||
| setCfgFractionalThreshold(_config.item<double_t>( | ||
| detector::FRACTIONAL_THRESHOLD, | ||
| detector::DEFAULT_FRACTIONAL_THRESHOLD)); | ||
|
|
||
| setCfgNearFraction(_config.item<double_t>( | ||
| detector::NEAR_FRACTION, | ||
| detector::DEFAULT_NEAR_FRACTION)); | ||
|
|
||
| setCfgSeverityFraction(_config.item<double_t>( | ||
| detector::SEVERITY_FRACTION, | ||
| detector::DEFAULT_SEVERITY_FRACTION)); | ||
|
|
||
| this->recalculateParams(); | ||
| } | ||
|
|
@@ -131,6 +97,49 @@ class SignalDropAnalyzer : public SignalAnalyzer { | |
| */ | ||
| void shiftBasePoints(); | ||
|
|
||
| //! int64_t | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type information in comment is redundant. |
||
| //! How far in the past we look. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could precise it a little bit: "Sets the number of previous iterations the algorithm takes in account" |
||
| void setCfgWindowSize(int64_t cfgWindowSize) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /s/setCfgWindowSize/setWindowSize The same applies below. |
||
| SignalDropAnalyzer::cfgWindowSize = cfgWindowSize; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is SignalDropAnalyzer::cfgWindowSize is static? Looks like ;) |
||
| } | ||
|
|
||
| //! int64_t | ||
| //! Maximum number of checkpoints we will have in our assurance detector. | ||
| //! Checkpoints are the reference assurance_test(base) points which we refer | ||
| //! to in the past when detecting drop or not. | ||
| //! It needs to be 0 < < WINDOW_SIZE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check this condition in setter... but it makes unfortunate time coupling with setWindowSize function - could we make something with that? We might need to create one setter for both those values. |
||
| void setCfgMaxCheckpoints(int64_t cfgMaxCheckpoints) { | ||
| SignalDropAnalyzer::cfgMaxCheckpoints = cfgMaxCheckpoints; | ||
| } | ||
|
|
||
| //! double_t | ||
| //! Fraction of checkpoints' votes that important decision needs to obtain. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "important decision needs to obtain" does not clears anything :) |
||
| void setCfgQuroum(double_t cfgQuroum) { | ||
| SignalDropAnalyzer::cfgQuroum = cfgQuroum; | ||
| } | ||
|
|
||
| //! double_t | ||
| //! Defines how much (relatively to base point) value must drop to trigger | ||
| //! contention. | ||
| //! Most signal_analyzer will use that. | ||
| void setCfgFractionalThreshold(double_t cfgFractionalThreshold) { | ||
| SignalDropAnalyzer::cfgFractionalThreshold = cfgFractionalThreshold; | ||
| } | ||
|
|
||
| //! double_t | ||
| //! You can adjust how big severity is created for a defined drop. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you should also write what 'severity' is. |
||
| //! if -1 then unknown severity will be reported. | ||
| void setCfgSeverityFraction(double_t cfgSeverityFraction) { | ||
| SignalDropAnalyzer::cfgSeverityFraction = cfgSeverityFraction; | ||
| } | ||
|
|
||
| //! double_t | ||
| //! Tolerance fraction of threshold if signal is accepted as returned to | ||
| //! previous state after drop. | ||
| void setCfgNearFraction(double_t cfgNearFraction) { | ||
| SignalDropAnalyzer::cfgNearFraction = cfgNearFraction; | ||
| } | ||
|
|
||
| protected: | ||
| std::list<double_t> window; | ||
| std::list<std::list<double_t>::iterator> basePoints; | ||
|
|
@@ -142,16 +151,16 @@ class SignalDropAnalyzer : public SignalAnalyzer { | |
| uint32_t quorumNum; | ||
|
|
||
| // cfg parameters. | ||
| uint64_t cfgWindowSize; | ||
| uint64_t cfgMaxCheckpoints; | ||
| int64_t cfgWindowSize; | ||
| int64_t cfgMaxCheckpoints; | ||
| double_t cfgQuroum; | ||
| double_t cfgFractionalThreshold; | ||
| double_t cfgSeverityFraction; | ||
| double_t cfgNearFraction; | ||
|
|
||
| /** | ||
| * It is possible to dynamically change analyzer configuration. | ||
| */ | ||
| * It is possible to dynamically change analyzer configuration. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is rather not helpful. |
||
| */ | ||
| void recalculateParams(); | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment no longer apply here. And bellow.
Comments lie all the times.