From commits-return-21921-archive-asf-public=cust-asf.ponee.io@mesos.apache.org Sat Apr 28 01:20:49 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1F76718067E for ; Sat, 28 Apr 2018 01:20:48 +0200 (CEST) Received: (qmail 30774 invoked by uid 500); 27 Apr 2018 23:20:48 -0000 Mailing-List: contact commits-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list commits@mesos.apache.org Received: (qmail 30656 invoked by uid 99); 27 Apr 2018 23:20:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Apr 2018 23:20:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B5D15F3263; Fri, 27 Apr 2018 23:20:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gilbert@apache.org To: commits@mesos.apache.org Date: Fri, 27 Apr 2018 23:20:49 -0000 Message-Id: In-Reply-To: <27998162e3394cf6865c452327e6f485@git.apache.org> References: <27998162e3394cf6865c452327e6f485@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/4] mesos git commit: Renamed Gauge to PullGauge and documented differences to PushGauge. Renamed Gauge to PullGauge and documented differences to PushGauge. Given `PushGauge`, it makes sense to explicitly distinguish the two gauge types and document the the caveats of `PullGauge`. Review: https://reviews.apache.org/r/66831/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8fad04ef Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8fad04ef Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8fad04ef Branch: refs/heads/master Commit: 8fad04ef8e86949cba0de3a0e571dd138d581d68 Parents: 898ff1b Author: Benjamin Mahler Authored: Fri Apr 27 16:07:01 2018 -0700 Committer: Gilbert Song Committed: Fri Apr 27 16:20:10 2018 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/include/Makefile.am | 2 +- .../include/process/metrics/gauge.hpp | 58 --------------- .../include/process/metrics/metric.hpp | 2 +- .../include/process/metrics/pull_gauge.hpp | 77 ++++++++++++++++++++ 3rdparty/libprocess/include/process/system.hpp | 14 ++-- 3rdparty/libprocess/src/tests/metrics_tests.cpp | 51 +++++++------ 3rdparty/libprocess/src/tests/system_tests.cpp | 2 +- 7 files changed, 116 insertions(+), 90 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/8fad04ef/3rdparty/libprocess/include/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/Makefile.am b/3rdparty/libprocess/include/Makefile.am index 25520c2..1ddcc2d 100644 --- a/3rdparty/libprocess/include/Makefile.am +++ b/3rdparty/libprocess/include/Makefile.am @@ -46,7 +46,7 @@ nobase_include_HEADERS = \ process/mime.hpp \ process/mutex.hpp \ process/metrics/counter.hpp \ - process/metrics/gauge.hpp \ + process/metrics/pull_gauge.hpp \ process/metrics/push_gauge.hpp \ process/metrics/metric.hpp \ process/metrics/metrics.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/8fad04ef/3rdparty/libprocess/include/process/metrics/gauge.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/metrics/gauge.hpp b/3rdparty/libprocess/include/process/metrics/gauge.hpp deleted file mode 100644 index 474f8e8..0000000 --- a/3rdparty/libprocess/include/process/metrics/gauge.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -#ifndef __PROCESS_METRICS_GAUGE_HPP__ -#define __PROCESS_METRICS_GAUGE_HPP__ - -#include -#include -#include - -#include - -namespace process { -namespace metrics { - -// A Metric that represents an instantaneous value evaluated when -// 'value' is called. -class Gauge : public Metric -{ -public: - // 'name' is the unique name for the instance of Gauge being constructed. - // It will be the key exposed in the JSON endpoint. - // - // 'f' is the function that is called when the Metric value is requested. - // The user of `Gauge` must ensure that `f` is safe to execute up until - // the removal of the `Gauge` (via `process::metrics::remove(...)`) is - // complete. - Gauge(const std::string& name, const std::function()>& f) - : Metric(name, None()), data(new Data(f)) {} - - virtual ~Gauge() {} - - virtual Future value() const { return data->f(); } - -private: - struct Data - { - explicit Data(const std::function()>& _f) : f(_f) {} - - const std::function()> f; - }; - - std::shared_ptr data; -}; - -} // namespace metrics { -} // namespace process { - -#endif // __PROCESS_METRICS_GAUGE_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/8fad04ef/3rdparty/libprocess/include/process/metrics/metric.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/metrics/metric.hpp b/3rdparty/libprocess/include/process/metrics/metric.hpp index 21f162d..2c4a154 100644 --- a/3rdparty/libprocess/include/process/metrics/metric.hpp +++ b/3rdparty/libprocess/include/process/metrics/metric.hpp @@ -29,7 +29,7 @@ namespace process { namespace metrics { -// The base class for Metrics such as Counter and Gauge. +// The base class for Metrics. class Metric { public: virtual ~Metric() {} http://git-wip-us.apache.org/repos/asf/mesos/blob/8fad04ef/3rdparty/libprocess/include/process/metrics/pull_gauge.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/metrics/pull_gauge.hpp b/3rdparty/libprocess/include/process/metrics/pull_gauge.hpp new file mode 100644 index 0000000..5c2a227 --- /dev/null +++ b/3rdparty/libprocess/include/process/metrics/pull_gauge.hpp @@ -0,0 +1,77 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +#ifndef __PROCESS_METRICS_PULL_GAUGE_HPP__ +#define __PROCESS_METRICS_PULL_GAUGE_HPP__ + +#include +#include +#include + +#include + +namespace process { +namespace metrics { + +// A Metric that represents an instantaneous measurement of a value +// (e.g. number of items in a queue). +// +// A pull-based gauge differs from a push-based gauge in that the +// client does not need to worry about when to compute a new gauge +// value and instead provides the value function to invoke during +// metrics collection. This makes the client logic simpler but comes +// with significant performance disadvantages. If this function +// dispatches to a `Process`, metrics collection will be exposed to +// delays while the dispatches work their way through the event +// queues. Also, gauges can be expensive to compute (e.g. loop over +// all items while counting how many match a criteria) and therefore +// can lead to a performance degradation on critial `Process`es +// during metrics collection. +// +// NOTE: Due to the performance disadvantages of pull-based gauges, +// it is recommended to use push-based gauges where possible. +// Pull-based gauges should ideally (1) be used on `Process`es that +// experience very light load, and (2) use functions that do not +// perform heavyweight computation to compute the value (e.g. looping +// over a large collection). +class PullGauge : public Metric +{ +public: + // 'name' is the unique name for the instance of Gauge being constructed. + // It will be the key exposed in the JSON endpoint. + // + // 'f' is the function that is called when the Metric value is requested. + // The user of `Gauge` must ensure that `f` is safe to execute up until + // the removal of the `Gauge` (via `process::metrics::remove(...)`) is + // complete. + PullGauge(const std::string& name, const std::function()>& f) + : Metric(name, None()), data(new Data(f)) {} + + virtual ~PullGauge() {} + + virtual Future value() const { return data->f(); } + +private: + struct Data + { + explicit Data(const std::function()>& _f) : f(_f) {} + + const std::function()> f; + }; + + std::shared_ptr data; +}; + +} // namespace metrics { +} // namespace process { + +#endif // __PROCESS_METRICS_PULL_GAUGE_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/8fad04ef/3rdparty/libprocess/include/process/system.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/system.hpp b/3rdparty/libprocess/include/process/system.hpp index 6bd815d..81ded8a 100644 --- a/3rdparty/libprocess/include/process/system.hpp +++ b/3rdparty/libprocess/include/process/system.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -183,14 +183,14 @@ private: return http::OK(object, request.url.query.get("jsonp")); } - metrics::Gauge load_1min; - metrics::Gauge load_5min; - metrics::Gauge load_15min; + metrics::PullGauge load_1min; + metrics::PullGauge load_5min; + metrics::PullGauge load_15min; - metrics::Gauge cpus_total; + metrics::PullGauge cpus_total; - metrics::Gauge mem_total_bytes; - metrics::Gauge mem_free_bytes; + metrics::PullGauge mem_total_bytes; + metrics::PullGauge mem_free_bytes; }; } // namespace process { http://git-wip-us.apache.org/repos/asf/mesos/blob/8fad04ef/3rdparty/libprocess/src/tests/metrics_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/tests/metrics_tests.cpp b/3rdparty/libprocess/src/tests/metrics_tests.cpp index 3a68388..a5b41ed 100644 --- a/3rdparty/libprocess/src/tests/metrics_tests.cpp +++ b/3rdparty/libprocess/src/tests/metrics_tests.cpp @@ -30,8 +30,8 @@ #include #include -#include #include +#include #include #include @@ -48,7 +48,7 @@ using http::Response; using http::Unauthorized; using metrics::Counter; -using metrics::Gauge; +using metrics::PullGauge; using metrics::PushGauge; using metrics::Timer; @@ -66,7 +66,7 @@ using std::map; using std::string; using std::vector; -class GaugeProcess : public Process +class PullGaugeProcess : public Process { public: double get() @@ -145,14 +145,14 @@ TEST_F(MetricsTest, Counter) } -TEST_F(MetricsTest, THREADSAFE_Gauge) +TEST_F(MetricsTest, PullGauge) { - GaugeProcess process; - PID pid = spawn(&process); + PullGaugeProcess process; + PID pid = spawn(&process); ASSERT_TRUE(pid); - // Gauge with a value. - Gauge gauge("test/gauge", defer(pid, &GaugeProcess::get)); + // PullGauge with a value. + PullGauge gauge("test/gauge", defer(pid, &PullGaugeProcess::get)); AWAIT_READY(metrics::add(gauge)); @@ -161,7 +161,7 @@ TEST_F(MetricsTest, THREADSAFE_Gauge) AWAIT_READY(metrics::remove(gauge)); // Failing gauge. - gauge = Gauge("test/failedgauge", defer(pid, &GaugeProcess::fail)); + gauge = PullGauge("test/failedgauge", defer(pid, &PullGaugeProcess::fail)); AWAIT_READY(metrics::add(gauge)); @@ -244,14 +244,14 @@ TEST_F(MetricsTest, THREADSAFE_Snapshot) Clock::pause(); - // Add a gauge and a counter. - GaugeProcess process; - PID pid = spawn(&process); + // Add a pull-gauge and a counter. + PullGaugeProcess process; + PID pid = spawn(&process); ASSERT_TRUE(pid); - Gauge gauge("test/gauge", defer(pid, &GaugeProcess::get)); - Gauge gaugeFail("test/gauge_fail", defer(pid, &GaugeProcess::fail)); - Gauge gaugeConst("test/gauge_const", []() { return 99.0; }); + PullGauge gauge("test/gauge", defer(pid, &PullGaugeProcess::get)); + PullGauge gaugeFail("test/gauge_fail", defer(pid, &PullGaugeProcess::fail)); + PullGauge gaugeConst("test/gauge_const", []() { return 99.0; }); Counter counter("test/counter"); AWAIT_READY(metrics::add(gauge)); @@ -382,15 +382,22 @@ TEST_F(MetricsTest, THREADSAFE_SnapshotTimeout) // Advance the clock to avoid rate limit. Clock::advance(Seconds(1)); - // Add gauges and a counter. - GaugeProcess process; - PID pid = spawn(&process); + // Add pull-gauges and a counter. + PullGaugeProcess process; + PID pid = spawn(&process); ASSERT_TRUE(pid); - Gauge gauge("test/gauge", defer(pid, &GaugeProcess::get)); - Gauge gaugeFail("test/gauge_fail", defer(pid, &GaugeProcess::fail)); - Gauge gaugeTimeout("test/gauge_timeout", defer(pid, &GaugeProcess::pending)); - Counter counter("test/counter"); + PullGauge gauge( + "test/gauge", + defer(pid, &PullGaugeProcess::get)); + PullGauge gaugeFail( + "test/gauge_fail", + defer(pid, &PullGaugeProcess::fail)); + PullGauge gaugeTimeout( + "test/gauge_timeout", + defer(pid, &PullGaugeProcess::pending)); + Counter counter( + "test/counter"); AWAIT_READY(metrics::add(gauge)); AWAIT_READY(metrics::add(gaugeFail)); http://git-wip-us.apache.org/repos/asf/mesos/blob/8fad04ef/3rdparty/libprocess/src/tests/system_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/tests/system_tests.cpp b/3rdparty/libprocess/src/tests/system_tests.cpp index 17f2881..237523f 100644 --- a/3rdparty/libprocess/src/tests/system_tests.cpp +++ b/3rdparty/libprocess/src/tests/system_tests.cpp @@ -30,7 +30,7 @@ namespace http = process::http; using process::Future; // MESOS-1433 -// This test is disabled as the Gauges that are used for these metrics +// This test is disabled as the pull-gauges that are used for these metrics // may return Failures. In this case we do not put the metric into the // endpoint. This has been observed specifically for the memory // metrics. If in the future we put the error message from the Failure