Commit f099d2b4 authored by Adam Simpkins's avatar Adam Simpkins Committed by Viswanath Sivakumar

expose FunctionScheduler::addFunction() with a custom distribution

Summary:
Make addFunctionInternal() publicly available, as an overloaded version of
addFunction().  This allows users to add functions with a specified poisson
distribution.

This allows us to deprecate our internal legacy version of FunctionScheduler,
and replace it with the folly version.

Test Plan: Confirmed all unit tests still pass.

Reviewed By: ldbrandy@fb.com

Subscribers: jwatzman, doug, net-systems@, exa, folly-diffs@, yfeldblum, chalfant

FB internal diff: D2051699

Signature: t1:2051699:1431379841:f3547d1ed371503b0bf91b509a4ef03e881aa991
parent 6d88461a
...@@ -38,11 +38,10 @@ void FunctionScheduler::addFunction(const std::function<void()>& cb, ...@@ -38,11 +38,10 @@ void FunctionScheduler::addFunction(const std::function<void()>& cb,
StringPiece nameID, StringPiece nameID,
milliseconds startDelay) { milliseconds startDelay) {
LatencyDistribution latencyDistr(false, 0.0); LatencyDistribution latencyDistr(false, 0.0);
addFunctionInternal(cb, interval, addFunction(cb, interval, latencyDistr, nameID, startDelay);
latencyDistr, nameID, startDelay);
} }
void FunctionScheduler::addFunctionInternal(const std::function<void()>& cb, void FunctionScheduler::addFunction(const std::function<void()>& cb,
milliseconds interval, milliseconds interval,
const LatencyDistribution& latencyDistr, const LatencyDistribution& latencyDistr,
StringPiece nameID, StringPiece nameID,
......
...@@ -64,16 +64,23 @@ class FunctionScheduler { ...@@ -64,16 +64,23 @@ class FunctionScheduler {
*/ */
void setSteady(bool steady) { steady_ = steady; } void setSteady(bool steady) { steady_ = steady; }
/*
* Parameters to control the function interval.
*
* If isPoisson is true, then use std::poisson_distribution to pick the
* interval between each invocation of the function.
*
* If isPoisson os false, then always use fixed the interval specified to
* addFunction().
*/
struct LatencyDistribution { struct LatencyDistribution {
bool isPoisson; bool isPoisson;
double poissonMean; double poissonMean;
LatencyDistribution(bool poisson, LatencyDistribution(bool poisson, double mean)
double mean)
: isPoisson(poisson), : isPoisson(poisson),
poissonMean(mean) { poissonMean(mean) {
} }
}; };
/** /**
...@@ -93,6 +100,17 @@ class FunctionScheduler { ...@@ -93,6 +100,17 @@ class FunctionScheduler {
std::chrono::milliseconds startDelay = std::chrono::milliseconds startDelay =
std::chrono::milliseconds(0)); std::chrono::milliseconds(0));
/*
* Add a new function to the FunctionScheduler with a specified
* LatencyDistribution
*/
void addFunction(const std::function<void()>& cb,
std::chrono::milliseconds interval,
const LatencyDistribution& latencyDistr,
StringPiece nameID = StringPiece(),
std::chrono::milliseconds startDelay =
std::chrono::milliseconds(0));
/** /**
* Cancels the function with the specified name, so it will no longer be run. * Cancels the function with the specified name, so it will no longer be run.
* *
...@@ -126,12 +144,6 @@ class FunctionScheduler { ...@@ -126,12 +144,6 @@ class FunctionScheduler {
private: private:
void addFunctionInternal(const std::function<void()>& cb,
std::chrono::milliseconds interval,
const LatencyDistribution& latencyDistr,
StringPiece nameID = StringPiece(),
std::chrono::milliseconds startDelay =
std::chrono::milliseconds(0));
struct RepeatFunc { struct RepeatFunc {
std::function<void()> cb; std::function<void()> cb;
std::chrono::milliseconds timeInterval; std::chrono::milliseconds timeInterval;
......
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