You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/01/22 22:41:57 UTC

[4/8] git commit: Reverted metering from Statistics.

Reverted metering from Statistics.

Review: https://reviews.apache.org/r/12766


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/20d3d44c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/20d3d44c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/20d3d44c

Branch: refs/heads/master
Commit: 20d3d44c79997a7762ddfc19e877f2cb56be3769
Parents: 10ccc77
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Thu Jul 18 15:34:46 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Wed Jan 22 13:03:11 2014 -0800

----------------------------------------------------------------------
 .../libprocess/include/process/statistics.hpp   | 75 +-----------------
 3rdparty/libprocess/src/statistics.cpp          | 70 +----------------
 .../libprocess/src/tests/statistics_tests.cpp   | 81 ++------------------
 3 files changed, 11 insertions(+), 215 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/20d3d44c/3rdparty/libprocess/include/process/statistics.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/statistics.hpp b/3rdparty/libprocess/include/process/statistics.hpp
index ce122a5..8592c4a 100644
--- a/3rdparty/libprocess/include/process/statistics.hpp
+++ b/3rdparty/libprocess/include/process/statistics.hpp
@@ -17,12 +17,6 @@ namespace process {
 class Statistics;
 class StatisticsProcess;
 
-namespace meters {
-  class Meter;
-  class TimeRate;
-}
-
-
 // Libprocess statistics handle.
 // To be used from anywhere to manage statistics.
 //
@@ -67,16 +61,6 @@ public:
   process::Future<std::map<std::string, double> > get(
       const std::string& context);
 
-  // Adds a meter for the statistic with the provided context and name.
-  //   get(context, meter->name) will return the metered time series.
-  // Returns an error if:
-  //   -meter->name == name, or
-  //   -The meter already exists.
-  Future<Try<Nothing> > meter(
-      const std::string& context,
-      const std::string& name,
-      Owned<meters::Meter> meter);
-
   // Sets the current value of a statistic at the current clock time
   // or at a specified time.
   void set(
@@ -85,12 +69,11 @@ public:
       double value,
       const Time& time = Clock::now());
 
-  // Archives the provided statistic time series, and any meters associated
-  // with it. This means three things:
+  // Archives the provided statistic time series.
+  // This means two things:
   //   1. The statistic will no longer be part of the snapshot.
-  //   2. However, the time series will be retained until the window expiration.
-  //   3. All meters associated with this statistic will be removed, both
-  //      (1) and (2) will apply to the metered time series as well.
+  //   2. However, the time series will be retained until the window
+  //      expiration.
   void archive(const std::string& context, const std::string& name);
 
   // Increments the current value of a statistic. If no statistic was
@@ -105,56 +88,6 @@ private:
   StatisticsProcess* process;
 };
 
-
-namespace meters {
-
-// This is the interface for statistical meters.
-// Meters provide additional metering on top of the raw statistical
-// value. Ex: Track the maximum, average, rate, etc.
-class Meter
-{
-protected:
-  Meter(const std::string& _name) : name(_name) {}
-
-public:
-  virtual ~Meter() {}
-
-  // Updates the meter with another input value.
-  // Returns the new metered value, or none if no metered value can be produced.
-  virtual Option<double> update(const Time& time, double value) = 0;
-
-  const std::string name;
-};
-
-
-// Tracks the percent of time 'used' since the last update.
-// Input values to this meter must be in seconds.
-class TimeRate : public Meter
-{
-public:
-  TimeRate(const std::string& name)
-    : Meter(name), time(None()), value(0) {}
-
-  virtual ~TimeRate() {}
-
-  virtual Option<double> update(const Time& _time, double _value)
-  {
-    Option<double> rate;
-    if (time.isSome()) {
-      rate = (_value - value) / (_time - time.get()).secs();
-    }
-
-    time = _time;
-    value = _value;
-    return rate;
-  }
-
-private:
-  Option<Time> time;
-  double value;
-};
-
-} // namespace meters {
 } // namespace process {
 
 #endif // __PROCESS_STATISTICS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/20d3d44c/3rdparty/libprocess/src/statistics.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/statistics.cpp b/3rdparty/libprocess/src/statistics.cpp
index d4ba9f1..07990d1 100644
--- a/3rdparty/libprocess/src/statistics.cpp
+++ b/3rdparty/libprocess/src/statistics.cpp
@@ -43,7 +43,8 @@ namespace process {
 Statistics* statistics = NULL;
 
 // TODO(bmahler): Move time series related logic into this struct.
-// TODO(bmahler): Investigate using google's btree implementation.
+// TODO(bmahler): Investigate using Google's sparse_hash_map.
+// Also investigate using Google's btree implementation.
 // This provides better insertion and lookup performance for large
 // containers. This _should_ also provide significant memory
 // savings, especially since:
@@ -82,11 +83,6 @@ public:
 
   map<string, double> get(const string& context);
 
-  Try<Nothing> meter(
-      const string& context,
-      const string& name,
-      const Owned<meters::Meter>& meter);
-
   void set(
       const string& context,
       const string& name,
@@ -137,10 +133,6 @@ private:
 
   // This maps from {context: {name: TimeSeries } }.
   hashmap<string, hashmap<string, TimeSeries> > statistics;
-
-  // Each statistic can have many meters.
-  // This maps from {context: {name: [meters] } }.
-  hashmap<string, hashmap<string, list<Owned<meters::Meter> > > > meters;
 };
 
 
@@ -170,33 +162,6 @@ const string StatisticsProcess::SNAPSHOT_HELP = HELP(
         ">        param=VALUE          Some description here"));
 
 
-Try<Nothing> StatisticsProcess::meter(
-    const string& context,
-    const string& name,
-    const Owned<meters::Meter>& meter)
-{
-  if (meter->name == name) {
-    return Error("Meter name must not match the statistic name");
-  }
-
-  // Check for a duplicate meter.
-  foreachkey (const string& context, meters) {
-    foreachkey (const string& name, meters[context]) {
-      foreach (Owned<meters::Meter>& existing, meters[context][name]) {
-        if (meter->name == existing->name) {
-          return Error("Meter name matched existing meter name");
-        }
-      }
-    }
-  }
-
-  // Add the meter.
-  meters[context][name].push_back(meter);
-
-  return Nothing();
-}
-
-
 map<Time, double> StatisticsProcess::timeseries(
     const string& context,
     const string& name,
@@ -262,19 +227,6 @@ void StatisticsProcess::set(
   statistics[context][name].archived = false;     // Unarchive.
 
   truncate(context, name);
-
-  // Update the metered values, if necessary.
-  if (meters.contains(context) && meters[context].contains(name)) {
-    foreach (Owned<meters::Meter>& meter, meters[context][name]) {
-      const Option<double>& update = meter->update(time, value);
-      statistics[context][meter->name].archived = false; // Unarchive.
-
-      if (update.isSome()) {
-        statistics[context][meter->name].values[time] = update.get();
-        truncate(context, meter->name);
-      }
-    }
-  }
 }
 
 
@@ -282,14 +234,6 @@ void StatisticsProcess::archive(const string& context, const string& name)
 {
   // Exclude the statistic from the snapshot.
   statistics[context][name].archived = true;
-
-  // Remove any meters as well.
-  if (meters.contains(context) && meters[context].contains(name)) {
-    foreach (const Owned<meters::Meter>& meter, meters[context][name]) {
-      statistics[context][meter->name].archived = true;
-    }
-    meters[context].erase(name);
-  }
 }
 
 
@@ -498,16 +442,6 @@ Future<map<string, double> > Statistics::get(const string& context)
 }
 
 
-Future<Try<Nothing> > Statistics::meter(
-    const string& context,
-    const string& name,
-    Owned<meters::Meter> meter)
-{
-
-  return dispatch(process, &StatisticsProcess::meter, context, name, meter);
-}
-
-
 void Statistics::set(
     const string& context,
     const string& name,

http://git-wip-us.apache.org/repos/asf/mesos/blob/20d3d44c/3rdparty/libprocess/src/tests/statistics_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/statistics_tests.cpp b/3rdparty/libprocess/src/tests/statistics_tests.cpp
index e6c9a1b..1acf47c 100644
--- a/3rdparty/libprocess/src/tests/statistics_tests.cpp
+++ b/3rdparty/libprocess/src/tests/statistics_tests.cpp
@@ -75,81 +75,20 @@ TEST(Statistics, truncate)
 }
 
 
-TEST(Statistics, meter) {
-  Statistics statistics(Days(1));
-
-  // Set up a meter, and ensure it captures the expected time rate.
-  Future<Try<Nothing> > meter =
-    statistics.meter(
-        "test",
-        "statistic",
-        Owned<meters::Meter>(new meters::TimeRate("metered")));
-
-  AWAIT_ASSERT_READY(meter);
-
-  ASSERT_TRUE(meter.get().isSome());
-
-  Time now = Clock::now();
-  statistics.set("test", "statistic", 1.0, now);
-  statistics.set("test", "statistic", 2.0, Time(now + Seconds(1)));
-  statistics.set("test", "statistic", 4.0, Time(now + Seconds(2)));
-
-  // Check the raw statistic values.
-  Future<map<Time, double> > values =
-    statistics.timeseries("test", "statistic");
-
-  AWAIT_ASSERT_READY(values);
-
-  EXPECT_EQ(3, values.get().size());
-  EXPECT_EQ(1, values.get().count(now));
-  EXPECT_EQ(1, values.get().count(Time(now + Seconds(1))));
-  EXPECT_EQ(1, values.get().count(Time(now + Seconds(2))));
-
-  EXPECT_EQ(1.0, values.get()[now]);
-  EXPECT_EQ(2.0, values.get()[Time(now + Seconds(1))]);
-  EXPECT_EQ(4.0, values.get()[Time(now + Seconds(2))]);
-
-  // Now check the metered values.
-  values = statistics.timeseries("test", "metered");
-
-  AWAIT_ASSERT_READY(values);
-
-  EXPECT_EQ(2, values.get().size());
-  EXPECT_EQ(1, values.get().count(Time(now + Seconds(1))));
-  EXPECT_EQ(1, values.get().count(Time(now + Seconds(2))));
-
-  EXPECT_EQ(0., values.get()[now]);
-  EXPECT_EQ(1.0, values.get()[Time(now + Seconds(1))]); // 100%.
-  EXPECT_EQ(2.0, values.get()[Time(now + Seconds(2))]); // 200%.
-}
-
-
 TEST(Statistics, archive)
 {
   Clock::pause();
 
   Statistics statistics(Seconds(10));
 
-  // Create a meter and a statistic for archival.
-  // Set up a meter, and ensure it captures the expected time rate.
-  Future<Try<Nothing> > meter =
-    statistics.meter(
-        "test",
-        "statistic",
-        Owned<meters::Meter>(new meters::TimeRate("metered")));
-
-  AWAIT_ASSERT_READY(meter);
-
-  ASSERT_TRUE(meter.get().isSome());
-
   Time now = Clock::now();
   statistics.set("test", "statistic", 1.0, now);
   statistics.set("test", "statistic", 2.0, Time(now + Seconds(1)));
 
   // Archive and ensure the following:
   //   1. The statistic will no longer be part of the snapshot.
-  //   2. Any meters associated with this statistic will be removed.
-  //   3. However, the time series will be retained until the window expiration.
+  //   2. However, the time series will be retained until the window
+  //      expiration.
   statistics.archive("test", "statistic");
 
   // TODO(bmahler): Wait for JSON parsing to verify number 1.
@@ -160,11 +99,6 @@ TEST(Statistics, archive)
   AWAIT_ASSERT_READY(values);
   EXPECT_FALSE(values.get().empty());
 
-  // Ensure the metered timeseries is present.
-  values = statistics.timeseries("test", "metered");
-  AWAIT_ASSERT_READY(values);
-  EXPECT_FALSE(values.get().empty());
-
   // Expire the window and ensure the statistics were removed.
   Clock::advance(STATISTICS_TRUNCATION_INTERVAL);
   Clock::settle();
@@ -174,17 +108,12 @@ TEST(Statistics, archive)
   AWAIT_ASSERT_READY(values);
   EXPECT_TRUE(values.get().empty());
 
-  // Ensure the metered statistics are gone.
-  values = statistics.timeseries("test", "metered");
-  AWAIT_ASSERT_READY(values);
-  EXPECT_TRUE(values.get().empty());
-
-  // Reactivate the statistic, and make sure the meter is still missing.
+  // Reactivate the statistic, and make sure we can retrieve it.
   statistics.set("test", "statistic", 1.0, now);
 
-  values = statistics.timeseries("test", "metered");
+  values = statistics.timeseries("test", "statistic");
   AWAIT_ASSERT_READY(values);
-  EXPECT_TRUE(values.get().empty());
+  EXPECT_FALSE(values.get().empty());
 
   Clock::resume();
 }