expose FunctionScheduler::addFunction() with a custom distribution
authorAdam Simpkins <simpkins@fb.com>
Tue, 12 May 2015 01:32:56 +0000 (18:32 -0700)
committerViswanath Sivakumar <viswanath@fb.com>
Wed, 20 May 2015 17:56:53 +0000 (10:56 -0700)
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

folly/experimental/FunctionScheduler.cpp
folly/experimental/FunctionScheduler.h

index b2c637aaa181c84a42639edee315b71079f995b4..e9ea7543c1eb9f4ec3263239f9e1925c8da0b673 100644 (file)
@@ -38,11 +38,10 @@ void FunctionScheduler::addFunction(const std::function<void()>& cb,
                                     StringPiece nameID,
                                     milliseconds startDelay) {
   LatencyDistribution latencyDistr(false, 0.0);
-  addFunctionInternal(cb, interval,
-                      latencyDistr, nameID, startDelay);
+  addFunction(cb, interval, latencyDistr, nameID, startDelay);
 }
 
-void FunctionScheduler::addFunctionInternal(const std::function<void()>& cb,
+void FunctionScheduler::addFunction(const std::function<void()>& cb,
                                     milliseconds interval,
                                     const LatencyDistribution& latencyDistr,
                                     StringPiece nameID,
index 896cb1fdb57424d84959edaa19c635f8e6c7ed80..1e8802fe06b6974e50eb375e9b67249e39ae2892 100644 (file)
@@ -64,16 +64,23 @@ class FunctionScheduler {
    */
   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 {
     bool isPoisson;
     double poissonMean;
 
-    LatencyDistribution(bool poisson,
-                 double mean)
+    LatencyDistribution(bool poisson, double mean)
       : isPoisson(poisson),
         poissonMean(mean) {
     }
-
   };
 
   /**
@@ -93,6 +100,17 @@ class FunctionScheduler {
                    std::chrono::milliseconds startDelay =
                      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.
    *
@@ -126,12 +144,6 @@ class FunctionScheduler {
 
 
  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 {
     std::function<void()> cb;
     std::chrono::milliseconds timeInterval;