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 2013/08/10 02:46:44 UTC

[5/5] git commit: Fixed a performance issue in Master::Http::stats().

Fixed a performance issue in Master::Http::stats().

We spent a lot of time doing unnecessary range additions
(e.g. ports resources).

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/13433


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

Branch: refs/heads/master
Commit: 699d708573737ea0225134bdcaf58f064eda3711
Parents: b26a133
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Fri Aug 9 17:22:49 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Fri Aug 9 17:32:24 2013 -0700

----------------------------------------------------------------------
 src/master/http.cpp | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/699d7085/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index ca66d67..1ac84a9 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -312,22 +312,32 @@ Future<Response> Master::Http::stats(const Request& request)
   Resources totalResources;
   Resources usedResources;
   foreachvalue (Slave* slave, master.slaves) {
-    totalResources += slave->info.resources();
-    usedResources += slave->resourcesInUse;
+    // Instead of accumulating all types of resources (which is
+    // not necessary), we only accumulate scalar resources. This
+    // helps us bypass a performance problem caused by range
+    // additions (e.g. ports).
+    foreach (const Resource& resource, slave->info.resources()) {
+      if (resource.type() == Value::SCALAR) {
+        totalResources += resource;
+      }
+    }
+    foreach (const Resource& resource, slave->resourcesInUse) {
+      if (resource.type() == Value::SCALAR) {
+        usedResources += resource;
+      }
+    }
   }
 
   foreach (const Resource& resource, totalResources) {
-    if (resource.type() == Value::SCALAR) {
-      CHECK(resource.has_scalar());
-      double total = resource.scalar().value();
-      object.values[resource.name() + "_total"] = total;
-      Option<Resource> option = usedResources.get(resource);
-      CHECK(!option.isSome() || option.get().has_scalar());
-      double used = option.isSome() ? option.get().scalar().value() : 0.0;
-      object.values[resource.name() + "_used"] = used;
-      double percent = used / total;
-      object.values[resource.name() + "_percent"] = percent;
-    }
+    CHECK(resource.has_scalar());
+    double total = resource.scalar().value();
+    object.values[resource.name() + "_total"] = total;
+    Option<Resource> option = usedResources.get(resource);
+    CHECK(!option.isSome() || option.get().has_scalar());
+    double used = option.isSome() ? option.get().scalar().value() : 0.0;
+    object.values[resource.name() + "_used"] = used;
+    double percent = used / total;
+    object.values[resource.name() + "_percent"] = percent;
   }
 
   return OK(object, request.query.get("jsonp"));