You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mz...@apache.org on 2019/08/23 21:51:48 UTC
[mesos] 04/04: Used boost `small_vector` in `Resources`.
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 73033130de7872c6f240b9b05dced039d7666138
Author: Meng Zhu <mz...@mesosphere.io>
AuthorDate: Thu Aug 22 17:19:30 2019 -0700
Used boost `small_vector` in `Resources`.
Master + previous patch:
*HierarchicalAllocator_WithQuotaParam.LargeAndSmallQuota/2
Made 3500 allocations in 16.307044003secs
Made 0 allocation in 14.948262599secs
Master + previous patch + this patch:
*HierarchicalAllocator_WithQuotaParam.LargeAndSmallQuota/2
Made 3500 allocations in 15.385276405secs
Made 0 allocation in 13.718502414secs
Review: https://reviews.apache.org/r/71357
---
include/mesos/resources.hpp | 20 ++++++++++++--------
include/mesos/v1/resources.hpp | 20 ++++++++++++--------
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index e5e87a0..b8aef28 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
+#include <boost/container/small_vector.hpp>
#include <boost/iterator/indirect_iterator.hpp>
#include <google/protobuf/repeated_field.h>
@@ -630,21 +631,19 @@ public:
// iterators to prevent mutable access to the `Resource` objects.
typedef boost::indirect_iterator<
- std::vector<Resource_Unsafe>::const_iterator>
+ boost::container::small_vector_base<Resource_Unsafe>::const_iterator>
const_iterator;
const_iterator begin()
{
- return static_cast<const std::vector<Resource_Unsafe>&>(
- resourcesNoMutationWithoutExclusiveOwnership)
- .begin();
+ const auto& self = *this;
+ return self.begin();
}
const_iterator end()
{
- return static_cast<const std::vector<Resource_Unsafe>&>(
- resourcesNoMutationWithoutExclusiveOwnership)
- .end();
+ const auto& self = *this;
+ return self.end();
}
const_iterator begin() const
@@ -754,7 +753,12 @@ private:
//
// TODO(mzhu): Consider using `boost::intrusive_ptr` for
// possibly better performance.
- std::vector<Resource_Unsafe> resourcesNoMutationWithoutExclusiveOwnership;
+ //
+ // We chose a size of 15 based on the fact that we have five first class
+ // resources (cpu, mem, disk, gpu and port). And 15 would allow one set of
+ // unreserved resources and two sets of reservations.
+ boost::container::small_vector<Resource_Unsafe, 15>
+ resourcesNoMutationWithoutExclusiveOwnership;
};
diff --git a/include/mesos/v1/resources.hpp b/include/mesos/v1/resources.hpp
index 6a9751a..3fbe7fb 100644
--- a/include/mesos/v1/resources.hpp
+++ b/include/mesos/v1/resources.hpp
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
+#include <boost/container/small_vector.hpp>
#include <boost/iterator/indirect_iterator.hpp>
#include <google/protobuf/repeated_field.h>
@@ -625,21 +626,19 @@ public:
// iterators to prevent mutable access to the `Resource` objects.
typedef boost::indirect_iterator<
- std::vector<Resource_Unsafe>::const_iterator>
+ boost::container::small_vector_base<Resource_Unsafe>::const_iterator>
const_iterator;
const_iterator begin()
{
- return static_cast<const std::vector<Resource_Unsafe>&>(
- resourcesNoMutationWithoutExclusiveOwnership)
- .begin();
+ const auto& self = *this;
+ return self.begin();
}
const_iterator end()
{
- return static_cast<const std::vector<Resource_Unsafe>&>(
- resourcesNoMutationWithoutExclusiveOwnership)
- .end();
+ const auto& self = *this;
+ return self.end();
}
const_iterator begin() const
@@ -749,7 +748,12 @@ private:
//
// TODO(mzhu): Consider using `boost::intrusive_ptr` for
// possibly better performance.
- std::vector<Resource_Unsafe> resourcesNoMutationWithoutExclusiveOwnership;
+ //
+ // We chose a size of 15 based on the fact that we have five first class
+ // resources (cpu, mem, disk, gpu and port). And 15 would allow one set of
+ // unreserved resources and two sets of reservations.
+ boost::container::small_vector<Resource_Unsafe, 15>
+ resourcesNoMutationWithoutExclusiveOwnership;
};