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/06/30 00:09:25 UTC

mesos git commit: Added a dedicated benchmark for overlapping range resources.

Repository: mesos
Updated Branches:
  refs/heads/master 964a63bc4 -> e16e4cd8a


Added a dedicated benchmark for overlapping range resources.

Also removed the current range benchmark which could produce
misleading results for subtraction (See MESOS-8989).

Review: https://reviews.apache.org/r/67590/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e16e4cd8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e16e4cd8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e16e4cd8

Branch: refs/heads/master
Commit: e16e4cd8a3fa35d347e6f96b428764b836979ebd
Parents: 964a63b
Author: Meng Zhu <mz...@mesosphere.io>
Authored: Fri Jun 29 16:51:16 2018 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Jun 29 16:57:57 2018 -0700

----------------------------------------------------------------------
 src/tests/resources_tests.cpp | 117 +++++++++++++++++++++++++++++++------
 1 file changed, 98 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e16e4cd8/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index 0095b94..9475b6e 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -3644,24 +3644,6 @@ public:
     }
     reservations.totalOperations = 10;
 
-    // Test the performance of ranges using a fragmented range of
-    // ports: [1-2,4-5,7-8,...,1000]. Note that the benchmark will
-    // continuously sum together the same port range, which does
-    // not preserve arithmetic invariants (a+a-a != a).
-    string ports;
-    for (int portBegin = 1; portBegin < 1000-1; portBegin = portBegin + 3) {
-      if (!ports.empty()) {
-        ports += ",";
-      }
-      ports += stringify(portBegin) + "-" + stringify(portBegin+1);
-    }
-
-    // TODO(gyliu513): Move the ports resources benchmark test
-    // to a separate test class.
-    ScalarArithmeticParameter ranges;
-    ranges.resources = Resources::parse("ports:[" + ports + "]").get();
-    ranges.totalOperations = 1000;
-
     // Test a typical vector of scalars which include shared resources
     // (viz, shared persistent volumes).
     Resource disk = createDiskResource(
@@ -3673,7 +3655,6 @@ public:
 
     parameters_.push_back(std::move(scalars));
     parameters_.push_back(std::move(reservations));
-    parameters_.push_back(std::move(ranges));
     parameters_.push_back(std::move(shared));
 
     return parameters_;
@@ -3988,6 +3969,104 @@ TEST_P(Resources_Parse_BENCHMARK_Test, Parse)
   }
 }
 
+
+class Resources_Ranges_BENCHMARK_Test
+  : public MesosTest,
+    public ::testing::WithParamInterface<size_t> {};
+
+
+// Size "100" here means 100 sub-ranges. We choose to parameterize on number of
+// subranges because it's a dominant factor in the performance of range
+// arithmetic operations.
+INSTANTIATE_TEST_CASE_P(
+    ResourcesRangesSizes,
+    Resources_Ranges_BENCHMARK_Test,
+    ::testing::Values(10U, 100U, 1000U));
+
+
+// This test benchmarks the range arithmetic performance when the two
+// range operands have partial overlappings.
+TEST_P(Resources_Ranges_BENCHMARK_Test, ArithmeticOverlapping)
+{
+  const size_t totalOperations = 1000;
+
+  // We construct `ports1` and `ports2` such that each of their
+  // intervals partially overlaps with the other:
+  // ports1 = [1-6, 11-16, 21-26, ..., 991-996] (100 sub-ranges of [1-996])
+  // ports2 = [3-8, 13-18, 23-28, ..., 993-998] (100 sub-ranges of [1-998])
+  Value::Ranges ranges1, ranges2;
+  for (size_t i = 0, port1Index = 1, port2Index = 3, stride = 5; i < GetParam();
+       i++) {
+    *ranges1.add_range() = createRange(port1Index, port1Index + stride);
+    *ranges2.add_range() = createRange(port2Index, port2Index + stride);
+
+    port1Index += stride * 2;
+    port2Index += stride * 2;
+  }
+
+  Resources ports1 = createPorts(ranges1);
+  Resources ports2 = createPorts(ranges2);
+
+  auto printResult = [&](const string& operation, const Duration& elapsedTime) {
+    cout << "Took " << elapsedTime << " to perform " << totalOperations << " '"
+         << operation << "' operations on " << abbreviate(stringify(ports1), 27)
+         << ranges1.range(GetParam() - 1).begin() << "-"
+         << ranges1.range(GetParam() - 1).end() << "] and "
+         << abbreviate(stringify(ports2), 27) << ", "
+         << ranges2.range(GetParam() - 1).begin() << "-"
+         << ranges2.range(GetParam() - 1).end() << "] with " << GetParam()
+         << " sub-ranges" << endl;
+  };
+
+  Resources result;
+
+  Stopwatch watch;
+
+  Duration elapsedTime;
+
+  for (size_t i = 0; i < totalOperations; i++) {
+    result = ports1;
+
+    watch.start();
+    result += ports2;
+    watch.stop();
+
+    elapsedTime += watch.elapsed();
+  }
+
+  printResult("a += b", elapsedTime);
+
+  elapsedTime = Duration::zero();
+
+  for (size_t i = 0; i < totalOperations; i++) {
+    result = ports1;
+
+    watch.start();
+    result -= ports2;
+    watch.stop();
+
+    elapsedTime += watch.elapsed();
+  }
+
+  printResult("a -= b", elapsedTime);
+
+  watch.start();
+  for (size_t i = 0; i < totalOperations; i++) {
+    result = ports1 + ports2;
+  }
+  watch.stop();
+
+  printResult("a + b", watch.elapsed());
+
+  watch.start();
+  for (size_t i = 0; i < totalOperations; i++) {
+    result = ports1 - ports2;
+  }
+  watch.stop();
+
+  printResult("a - b", watch.elapsed());
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {