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/09/27 18:59:48 UTC

[mesos] 02/10: Reserve sort output vector in the sorters.

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

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

commit 61100f3f33970f618bea96f4ba3df9ae156b7af4
Author: Benjamin Mahler <bm...@apache.org>
AuthorDate: Sun Sep 16 16:36:10 2018 -0700

    Reserve sort output vector in the sorters.
    
    This reserves the sort output vector consistently based on
    the number of clients, in both the DRF and random sorters.
    
    Review: https://reviews.apache.org/r/68730
---
 src/master/allocator/sorter/drf/sorter.cpp    | 4 ++++
 src/master/allocator/sorter/random/sorter.cpp | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/src/master/allocator/sorter/drf/sorter.cpp b/src/master/allocator/sorter/drf/sorter.cpp
index aa925c4..a45f66f 100644
--- a/src/master/allocator/sorter/drf/sorter.cpp
+++ b/src/master/allocator/sorter/drf/sorter.cpp
@@ -551,6 +551,10 @@ vector<string> DRFSorter::sort()
   // inactive leaves sorted after active leaves and internal nodes.
   vector<string> result;
 
+  // TODO(bmahler): This over-reserves where there are inactive
+  // clients, only reserve the number of active clients.
+  result.reserve(clients.size());
+
   std::function<void (const Node*)> listClients =
       [&listClients, &result](const Node* node) {
     foreach (const Node* child, node->children) {
diff --git a/src/master/allocator/sorter/random/sorter.cpp b/src/master/allocator/sorter/random/sorter.cpp
index 7b98389..fc47756 100644
--- a/src/master/allocator/sorter/random/sorter.cpp
+++ b/src/master/allocator/sorter/random/sorter.cpp
@@ -497,6 +497,9 @@ vector<string> RandomSorter::sort()
   // The children of each node are already shuffled, with
   // inactive leaves stored after active leaves and internal nodes.
   vector<string> result;
+
+  // TODO(bmahler): This over-reserves where there are inactive
+  // clients, only reserve the number of active clients.
   result.reserve(clients.size());
 
   std::function<void (const Node*)> listClients =