Commit 5ca43e12 authored by Zhenyu Zhou's avatar Zhenyu Zhou Committed by Facebook Github Bot

Add a constructor to folly::Codel

Summary: Making a new ctor so that we can pass in the parameters

Reviewed By: yfeldblum

Differential Revision: D17173662

fbshipit-source-id: ab518892694e1bec1179177e7d9477e3a89ff38d
parent b36f6181
...@@ -27,7 +27,13 @@ using namespace std::chrono; ...@@ -27,7 +27,13 @@ using namespace std::chrono;
namespace folly { namespace folly {
Codel::Codel() Codel::Codel()
: codelMinDelayNs_(0), : Codel(Codel::Options()
.setInterval(milliseconds(FLAGS_codel_interval))
.setTargetDelay(milliseconds(FLAGS_codel_target_delay))) {}
Codel::Codel(const Options& options)
: options_(options),
codelMinDelayNs_(0),
codelIntervalTimeNs_( codelIntervalTimeNs_(
duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()) duration_cast<nanoseconds>(steady_clock::now().time_since_epoch())
.count()), .count()),
...@@ -91,11 +97,11 @@ nanoseconds Codel::getMinDelay() { ...@@ -91,11 +97,11 @@ nanoseconds Codel::getMinDelay() {
} }
milliseconds Codel::getInterval() { milliseconds Codel::getInterval() {
return milliseconds(FLAGS_codel_interval); return options_.interval();
} }
milliseconds Codel::getTargetDelay() { milliseconds Codel::getTargetDelay() {
return milliseconds(FLAGS_codel_target_delay); return options_.targetDelay();
} }
milliseconds Codel::getSloughTimeout() { milliseconds Codel::getSloughTimeout() {
......
...@@ -56,8 +56,36 @@ namespace folly { ...@@ -56,8 +56,36 @@ namespace folly {
/// 2. https://en.wikipedia.org/wiki/CoDel /// 2. https://en.wikipedia.org/wiki/CoDel
class Codel { class Codel {
public: public:
class Options {
public:
std::chrono::milliseconds interval() const {
return interval_;
}
Options& setInterval(std::chrono::milliseconds value) {
interval_ = value;
return *this;
}
std::chrono::milliseconds targetDelay() const {
return targetDelay_;
}
Options& setTargetDelay(std::chrono::milliseconds value) {
targetDelay_ = value;
return *this;
}
private:
std::chrono::milliseconds interval_;
std::chrono::milliseconds targetDelay_;
};
Codel(); Codel();
/// Preferable construction method
explicit Codel(const Options& options);
/// Returns true if this request should be expired to reduce overload. /// Returns true if this request should be expired to reduce overload.
/// In detail, this returns true if min_delay > target_delay for the /// In detail, this returns true if min_delay > target_delay for the
/// interval, and this delay > 2 * target_delay. /// interval, and this delay > 2 * target_delay.
...@@ -80,6 +108,7 @@ class Codel { ...@@ -80,6 +108,7 @@ class Codel {
std::chrono::milliseconds getSloughTimeout(); std::chrono::milliseconds getSloughTimeout();
private: private:
Options options_;
std::atomic<uint64_t> codelMinDelayNs_; std::atomic<uint64_t> codelMinDelayNs_;
std::atomic<uint64_t> codelIntervalTimeNs_; std::atomic<uint64_t> codelIntervalTimeNs_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment