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/12/17 04:15:27 UTC

[2/2] mesos git commit: Fixed the DRFSorter share calculation to not assume flattened resources.

Fixed the DRFSorter share calculation to not assume flattened resources.

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


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

Branch: refs/heads/master
Commit: d244b08cf1dad3e4494eb42cf902807754f355a3
Parents: df22aa8
Author: Benjamin Mahler <be...@gmail.com>
Authored: Mon Dec 15 21:26:05 2014 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Tue Dec 16 18:39:30 2014 -0800

----------------------------------------------------------------------
 src/master/drf_sorter.cpp  | 26 +++++++++++++++++---------
 src/tests/sorter_tests.cpp | 30 ++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d244b08c/src/master/drf_sorter.cpp
----------------------------------------------------------------------
diff --git a/src/master/drf_sorter.cpp b/src/master/drf_sorter.cpp
index 0ad6c52..ebc0284 100644
--- a/src/master/drf_sorter.cpp
+++ b/src/master/drf_sorter.cpp
@@ -217,24 +217,32 @@ double DRFSorter::calculateShare(const string& name)
 {
   double share = 0;
 
-  // TODO(benh): This implementaion of "dominant resource fairness"
+  // TODO(benh): This implementation of "dominant resource fairness"
   // currently does not take into account resources that are not
   // scalars.
 
+  // Scalar resources may be spread across multiple 'Resource'
+  // objects. E.g. persistent disks. So we first collect the names
+  // of the scalar resources, before computing the totals.
+  hashset<string> scalars;
   foreach (const Resource& resource, resources) {
     if (resource.type() == Value::SCALAR) {
-      double total = resource.scalar().value();
+      scalars.insert(resource.name());
+    }
+  }
 
-      if (total > 0) {
-        Option<Value::Scalar> scalar =
-          allocations[name].get<Value::Scalar>(resource.name());
+  foreach (const string& scalar, scalars) {
+    Option<Value::Scalar> total = resources.get<Value::Scalar>(scalar);
 
-        if (scalar.isNone()) {
-          scalar = Value::Scalar();
-        }
+    if (total.isSome() && total.get().value() > 0) {
+      Option<Value::Scalar> allocation =
+        allocations[name].get<Value::Scalar>(scalar);
 
-        share = std::max(share, scalar.get().value() / total);
+      if (allocation.isNone()) {
+        allocation = Value::Scalar();
       }
+
+      share = std::max(share, allocation.get().value() / total.get().value());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/d244b08c/src/tests/sorter_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/sorter_tests.cpp b/src/tests/sorter_tests.cpp
index b80f44d..c2f4aa1 100644
--- a/src/tests/sorter_tests.cpp
+++ b/src/tests/sorter_tests.cpp
@@ -164,3 +164,33 @@ TEST(SorterTest, WDRFSorter)
 
   EXPECT_EQ(list<string>({"c", "d", "e"}), sorter.sort());
 }
+
+
+// Some resources are split across multiple resource objects
+// (e.g. persistent disks). This test ensures that the shares
+// for these are accounted correctly.
+TEST(SorterTest, SplitResourceShares)
+{
+  DRFSorter sorter;
+
+  sorter.add("a");
+  sorter.add("b");
+
+  Resource disk1 = Resources::parse("disk", "5", "*").get();
+  disk1.mutable_disk()->mutable_persistence()->set_id("ID2");
+  disk1.mutable_disk()->mutable_volume()->set_container_path("data");
+
+  Resource disk2 = Resources::parse("disk", "5", "*").get();
+  disk2.mutable_disk()->mutable_persistence()->set_id("ID2");
+  disk2.mutable_disk()->mutable_volume()->set_container_path("data");
+
+  sorter.add(Resources::parse("cpus:100;mem:100;disk:95").get()
+             + disk1 + disk2);
+
+  // Now, allocate resources to "a" and "b". Note that "b" will have
+  // more disk if the shares are accounted correctly!
+  sorter.allocated("a", Resources::parse("cpus:9;mem:9;disk:9").get());
+  sorter.allocated("b", Resources::parse("cpus:9;mem:9").get() + disk1 + disk2);
+
+  EXPECT_EQ(list<string>({"a", "b"}), sorter.sort());
+}