You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ya...@apache.org on 2016/07/15 06:19:38 UTC
mesos git commit: Code cleanup in hierarchical_allocator_tests.cpp.
Repository: mesos
Updated Branches:
refs/heads/master 1a875ab04 -> 897b12fb3
Code cleanup in hierarchical_allocator_tests.cpp.
This patch fixed the following issues in benchmark test:
1) Enabled templatized test fixture for DeclineOffers and
ResourceLabels.
2) Updated the output for the benchmark to be more clear.
Review: https://reviews.apache.org/r/49781/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/897b12fb
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/897b12fb
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/897b12fb
Branch: refs/heads/master
Commit: 897b12fb3a00b7ad2ca0d322321426da3121d35b
Parents: 1a875ab
Author: Guangya Liu <gy...@gmail.com>
Authored: Thu Jul 14 23:18:32 2016 -0700
Committer: Jiang Yan Xu <xu...@apple.com>
Committed: Thu Jul 14 23:18:32 2016 -0700
----------------------------------------------------------------------
src/tests/hierarchical_allocator_tests.cpp | 89 ++++++++++---------------
1 file changed, 36 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/897b12fb/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 153c9b4..a3920de 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -3383,10 +3383,11 @@ TEST_P(HierarchicalAllocator_BENCHMARK_Test, AddAndUpdateSlave)
// This benchmark simulates a number of frameworks that have a fixed amount of
// work to do. Once they have reached their targets, they start declining all
// subsequent offers.
-TEST_F(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
+TEST_P(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
{
- unsigned frameworkCount = 200;
- unsigned slaveCount = 2000;
+ size_t slaveCount = std::tr1::get<0>(GetParam());
+ size_t frameworkCount = std::tr1::get<1>(GetParam());
+
master::Flags flags;
// Choose an interval longer than the time we expect a single cycle to take so
@@ -3396,10 +3397,6 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
// Pause the clock because we want to manually drive the allocations.
Clock::pause();
- // Number of allocations. This is used to determine the termination
- // condition.
- atomic<size_t> offerCount(0);
-
struct OfferedResources {
FrameworkID frameworkId;
SlaveID slaveId;
@@ -3408,7 +3405,7 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
vector<OfferedResources> offers;
- auto offerCallback = [&offerCount, &offers](
+ auto offerCallback = [&offers](
const FrameworkID& frameworkId,
const hashmap<SlaveID, Resources>& resources_)
{
@@ -3416,17 +3413,15 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
offers.push_back(
OfferedResources{frameworkId, resources.first, resources.second});
}
-
- offerCount++;
};
- vector<SlaveInfo> slaves;
- vector<FrameworkInfo> frameworks;
-
cout << "Using " << slaveCount << " agents and "
<< frameworkCount << " frameworks" << endl;
+ vector<SlaveInfo> slaves;
slaves.reserve(slaveCount);
+
+ vector<FrameworkInfo> frameworks;
frameworks.reserve(frameworkCount);
initialize(flags, offerCallback);
@@ -3440,7 +3435,6 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
"cpus:16;mem:2014;disk:1024;").get();
Resources ports = makePortRanges(makeRange(31000, 32000), 16);
-
resources += ports;
for (unsigned i = 0; i < slaveCount; i++) {
@@ -3459,7 +3453,7 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
Clock::settle();
// Loop enough times for all the frameworks to get offered all the resources.
- for (unsigned count = 0; count < frameworkCount * 2; count++) {
+ for (unsigned i = 0; i < frameworkCount * 2; i++) {
// Permanently decline any offered resources.
foreach (auto offer, offers) {
Filters filters;
@@ -3472,22 +3466,19 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, DeclineOffers)
// Wait for the declined offers.
Clock::settle();
offers.clear();
- offerCount = 0;
- {
- Stopwatch watch;
+ Stopwatch watch;
- watch.start();
+ watch.start();
- // Advance the clock and trigger a background allocation cycle.
- Clock::advance(flags.allocation_interval);
- Clock::settle();
+ // Advance the clock and trigger a background allocation cycle.
+ Clock::advance(flags.allocation_interval);
+ Clock::settle();
- cout << "round " << count
- << " allocate took " << watch.elapsed()
- << " to make " << offerCount.load() << " offers"
- << endl;
- }
+ cout << "round " << i
+ << " allocate() took " << watch.elapsed()
+ << " to make " << offers.size() << " offers"
+ << endl;
}
Clock::resume();
@@ -3523,10 +3514,11 @@ static Labels makeLabels(bool first, size_t labelId)
// TODO(neilc): Refactor to reduce code duplication with `DeclineOffers` test.
-TEST_F(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
+TEST_P(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
{
- unsigned frameworkCount = 200;
- unsigned slaveCount = 2000;
+ size_t slaveCount = std::tr1::get<0>(GetParam());
+ size_t frameworkCount = std::tr1::get<1>(GetParam());
+
master::Flags flags;
// Choose an interval longer than the time we expect a single cycle to take so
@@ -3536,10 +3528,6 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
// Pause the clock because we want to manually drive the allocations.
Clock::pause();
- // Number of allocations. This is used to determine the termination
- // condition.
- atomic<size_t> offerCount(0);
-
struct OfferedResources {
FrameworkID frameworkId;
SlaveID slaveId;
@@ -3548,7 +3536,7 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
vector<OfferedResources> offers;
- auto offerCallback = [&offerCount, &offers](
+ auto offerCallback = [&offers](
const FrameworkID& frameworkId,
const hashmap<SlaveID, Resources>& resources_)
{
@@ -3556,17 +3544,15 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
offers.push_back(
OfferedResources{frameworkId, resources.first, resources.second});
}
-
- offerCount++;
};
- vector<SlaveInfo> slaves;
- vector<FrameworkInfo> frameworks;
-
cout << "Using " << slaveCount << " agents and "
<< frameworkCount << " frameworks" << endl;
+ vector<SlaveInfo> slaves;
slaves.reserve(slaveCount);
+
+ vector<FrameworkInfo> frameworks;
frameworks.reserve(frameworkCount);
initialize(flags, offerCallback);
@@ -3619,7 +3605,7 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
Clock::settle();
// Loop enough times for all the frameworks to get offered all the resources.
- for (unsigned count = 0; count < frameworkCount * 2; count++) {
+ for (unsigned i = 0; i < frameworkCount * 2; i++) {
// Permanently decline any offered resources.
foreach (auto offer, offers) {
Filters filters;
@@ -3632,22 +3618,19 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
// Wait for the declined offers.
Clock::settle();
offers.clear();
- offerCount = 0;
- {
- Stopwatch watch;
+ Stopwatch watch;
- watch.start();
+ watch.start();
- // Advance the clock and trigger a background allocation cycle.
- Clock::advance(flags.allocation_interval);
- Clock::settle();
+ // Advance the clock and trigger a background allocation cycle.
+ Clock::advance(flags.allocation_interval);
+ Clock::settle();
- cout << "round " << count
- << " allocate took " << watch.elapsed()
- << " to make " << offerCount.load() << " offers"
- << endl;
- }
+ cout << "round " << i
+ << " allocate() took " << watch.elapsed()
+ << " to make " << offers.size() << " offers"
+ << endl;
}
Clock::resume();