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;
namespace folly {
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_(
duration_cast<nanoseconds>(steady_clock::now().time_since_epoch())
.count()),
......@@ -91,11 +97,11 @@ nanoseconds Codel::getMinDelay() {
}
milliseconds Codel::getInterval() {
return milliseconds(FLAGS_codel_interval);
return options_.interval();
}
milliseconds Codel::getTargetDelay() {
return milliseconds(FLAGS_codel_target_delay);
return options_.targetDelay();
}
milliseconds Codel::getSloughTimeout() {
......
......@@ -56,8 +56,36 @@ namespace folly {
/// 2. https://en.wikipedia.org/wiki/CoDel
class Codel {
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();
/// Preferable construction method
explicit Codel(const Options& options);
/// Returns true if this request should be expired to reduce overload.
/// In detail, this returns true if min_delay > target_delay for the
/// interval, and this delay > 2 * target_delay.
......@@ -80,6 +108,7 @@ class Codel {
std::chrono::milliseconds getSloughTimeout();
private:
Options options_;
std::atomic<uint64_t> codelMinDelayNs_;
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