This is an automated email from the ASF dual-hosted git repository. mzhu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 95201cbe4dc87eae2fde5754d16f5effbb6c1974 Author: Meng Zhu <[email protected]> AuthorDate: Thu Aug 22 16:55:34 2019 -0700 Used boost `small_vector` in Resource Quantities and Limits. Master + previous patch *HierarchicalAllocator_WithQuotaParam.LargeAndSmallQuota/2 Made 3500 allocations in 16.831380548secs Made 0 allocation in 15.102885644secs Master + previous patch + this patch: *HierarchicalAllocator_WithQuotaParam.LargeAndSmallQuota/2 Made 3500 allocations in 16.307044003secs Made 0 allocation in 14.948262599secs Review: https://reviews.apache.org/r/71355 --- include/mesos/resource_quantities.hpp | 33 ++++++++++++++++++++++----------- src/common/resource_quantities.cpp | 34 ++++++++++------------------------ 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/include/mesos/resource_quantities.hpp b/include/mesos/resource_quantities.hpp index cdb3427..8195d5e 100644 --- a/include/mesos/resource_quantities.hpp +++ b/include/mesos/resource_quantities.hpp @@ -19,7 +19,8 @@ #include <string> #include <utility> -#include <vector> + +#include <boost/container/small_vector.hpp> #include <mesos/mesos.hpp> @@ -118,10 +119,10 @@ public: ResourceQuantities& operator=(const ResourceQuantities& that) = default; ResourceQuantities& operator=(ResourceQuantities&& that) = default; - typedef std::vector<std::pair<std::string, Value::Scalar>>::const_iterator - iterator; - typedef std::vector<std::pair<std::string, Value::Scalar>>::const_iterator - const_iterator; + typedef boost::container::small_vector_base< + std::pair<std::string, Value::Scalar> >::const_iterator iterator; + typedef boost::container::small_vector_base< + std::pair<std::string, Value::Scalar> >::const_iterator const_iterator; // NOTE: Non-`const` `iterator`, `begin()` and `end()` are __intentionally__ // defined with `const` semantics in order to prevent mutation during @@ -159,7 +160,12 @@ private: // List of name quantity pairs sorted by name. // Arithmetic and comparison operations benefit from this sorting. - std::vector<std::pair<std::string, Value::Scalar>> quantities; + // + // Pre-allocate space for first-class resources, plus some margins. + // This needs to be updated as introduce more first-class resources. + // [cpus, disk, gpus, mem, ports] + boost::container::small_vector<std::pair<std::string, Value::Scalar>, 7> + quantities; }; @@ -212,10 +218,10 @@ public: ResourceLimits& operator=(const ResourceLimits& that) = default; ResourceLimits& operator=(ResourceLimits&& that) = default; - typedef std::vector<std::pair<std::string, Value::Scalar>>::const_iterator - iterator; - typedef std::vector<std::pair<std::string, Value::Scalar>>::const_iterator - const_iterator; + typedef boost::container::small_vector_base< + std::pair<std::string, Value::Scalar> >::const_iterator iterator; + typedef boost::container::small_vector_base< + std::pair<std::string, Value::Scalar> >::const_iterator const_iterator; // NOTE: Non-`const` `iterator`, `begin()` and `end()` are __intentionally__ // defined with `const` semantics in order to prevent mutation during @@ -258,7 +264,12 @@ private: // List of name limit pairs sorted by name. // Arithmetic and comparison operations benefit from this sorting. - std::vector<std::pair<std::string, Value::Scalar>> limits; + // + // Pre-allocate space for first-class resources, plus some margins. + // This needs to be updated as introduce more first-class resources. + // [cpus, disk, gpus, mem, ports] + boost::container::small_vector<std::pair<std::string, Value::Scalar>, 7> + limits; }; diff --git a/src/common/resource_quantities.cpp b/src/common/resource_quantities.cpp index 7c7ede3..8f487fb 100644 --- a/src/common/resource_quantities.cpp +++ b/src/common/resource_quantities.cpp @@ -131,12 +131,7 @@ ResourceQuantities ResourceQuantities::fromResources(const Resources& resources) } -ResourceQuantities::ResourceQuantities() -{ - // Pre-reserve space for first-class resources. - // [cpus, disk, gpus, mem, ports] - quantities.reserve(5u); -} +ResourceQuantities::ResourceQuantities() {} ResourceQuantities::ResourceQuantities( @@ -152,17 +147,15 @@ ResourceQuantities::ResourceQuantities( ResourceQuantities::const_iterator ResourceQuantities::begin() { - return static_cast<const std::vector<std::pair<std::string, Value::Scalar>>&>( - quantities) - .begin(); + const auto& self = *this; + return self.begin(); } ResourceQuantities::const_iterator ResourceQuantities::end() { - return static_cast<const std::vector<std::pair<std::string, Value::Scalar>>&>( - quantities) - .end(); + const auto& self = *this; + return self.end(); } @@ -407,12 +400,7 @@ Try<ResourceLimits> ResourceLimits::fromString(const string& text) } -ResourceLimits::ResourceLimits() -{ - // Pre-reserve space for first-class resources. - // [cpus, disk, gpus, mem, ports] - limits.reserve(5u); -} +ResourceLimits::ResourceLimits() {} ResourceLimits::ResourceLimits( @@ -428,17 +416,15 @@ ResourceLimits::ResourceLimits( ResourceLimits::const_iterator ResourceLimits::begin() { - return static_cast<const std::vector<std::pair<std::string, Value::Scalar>>&>( - limits) - .begin(); + const auto& self = *this; + return self.begin(); } ResourceLimits::const_iterator ResourceLimits::end() { - return static_cast<const std::vector<std::pair<std::string, Value::Scalar>>&>( - limits) - .end(); + const auto& self = *this; + return self.end(); }
