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 2018/10/18 01:37:55 UTC

[mesos] 02/02: Cached whether agents have gpus to improve allocator performance.

This is an automated email from the ASF dual-hosted git repository.

bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit f03f91545fec64a767f808c48a3b352dc86b1ac0
Author: Meng Zhu <mz...@mesosphere.io>
AuthorDate: Wed Oct 17 18:37:39 2018 -0700

    Cached whether agents have gpus to improve allocator performance.
    
    Due to the `filterGpuResources` mechanism, before making any
    allocations, the allocator needs to check if an agent has
    any GPU resources. This is currently done by calling the
    `Resources::gpus()` function which traverse the resource
    vector and copy the scalar. Since this is frequently called
    and agent total resources rarely change, caching this boolean
    will yield quite some performance improvement.
    
    Review: https://reviews.apache.org/r/69068/
---
 src/master/allocator/mesos/hierarchical.cpp | 2 +-
 src/master/allocator/mesos/hierarchical.hpp | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 6573142..c89a63d 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -2705,7 +2705,7 @@ bool HierarchicalAllocatorProcess::isCapableOfReceivingAgent(
   // frameworks that are capable of receiving GPUs.
   // See MESOS-5634.
   if (filterGpuResources && !frameworkCapabilities.gpuResources &&
-      slave.getTotal().gpus().getOrElse(0) > 0) {
+      slave.hasGpu()) {
     return false;
   }
 
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 1ea29a6..7b31c9d 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -115,7 +115,8 @@ public:
       activated(_activated),
       total(_total),
       allocated(_allocated),
-      shared(_total.shared())
+      shared(_total.shared()),
+      hasGpu_(_total.gpus().getOrElse(0) > 0)
   {
     updateAvailable();
   }
@@ -126,9 +127,12 @@ public:
 
   const Resources& getAvailable() const { return available; }
 
+  bool hasGpu() const { return hasGpu_; }
+
   void updateTotal(const Resources& newTotal) {
     total = newTotal;
     shared = total.shared();
+    hasGpu_ = total.gpus().getOrElse(0) > 0;
 
     updateAvailable();
   }
@@ -249,6 +253,9 @@ private:
 
   // We keep a copy of the shared resources to avoid unnecessary copying.
   Resources shared;
+
+  // We cache whether the agent has gpus as an optimization.
+  bool hasGpu_;
 };