You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/04/25 23:35:46 UTC

[05/48] mesos git commit: Allocator Performance: Simplified Sorter's 'CalculateShare'.

Allocator Performance: Simplified Sorter's 'CalculateShare'.

Used existing functions to aggregate Scalars in the 'Resources' object.

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


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

Branch: refs/heads/0.27.x
Commit: 0869c2db6f32c462656402bda48aa678f303e017
Parents: b956e2c
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Wed Jan 27 19:14:21 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Wed Jan 27 20:04:51 2016 -0800

----------------------------------------------------------------------
 src/master/allocator/sorter/drf/sorter.cpp | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0869c2db/src/master/allocator/sorter/drf/sorter.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/drf/sorter.cpp b/src/master/allocator/sorter/drf/sorter.cpp
index 1f39f6d..db47d64 100644
--- a/src/master/allocator/sorter/drf/sorter.cpp
+++ b/src/master/allocator/sorter/drf/sorter.cpp
@@ -346,24 +346,28 @@ double DRFSorter::calculateShare(const string& name)
   // scalars.
 
   foreach (const string& scalar, total_.scalars.names()) {
-    double _total = 0.0;
-
+    // We collect the scalar accumulated total value from the
+    // `Resources` object.
+    //
     // NOTE: Scalar resources may be spread across multiple
     // 'Resource' objects. E.g. persistent volumes.
-    foreach (const Resource& resource, total_.scalars.get(scalar)) {
-      CHECK_EQ(resource.type(), Value::SCALAR);
-      _total += resource.scalar().value();
-    }
+    Option<Value::Scalar> __total = total_.scalars.get<Value::Scalar>(scalar);
+    CHECK_SOME(__total);
+    const double _total = __total.get().value();
 
     if (_total > 0.0) {
       double allocation = 0.0;
 
+      // We collect the scalar accumulated allocation value from the
+      // `Resources` object.
+      //
       // NOTE: Scalar resources may be spread across multiple
       // 'Resource' objects. E.g. persistent volumes.
-      foreach (const Resource& resource,
-               allocations[name].scalars.get(scalar)) {
-        CHECK_EQ(resource.type(), Value::SCALAR);
-        allocation += resource.scalar().value();
+      Option<Value::Scalar> _allocation =
+        allocations[name].scalars.get<Value::Scalar>(scalar);
+
+      if (_allocation.isSome()) {
+        allocation = _allocation.get().value();
       }
 
       share = std::max(share, allocation / _total);