quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbdeshm...@apache.org
Subject [1/3] incubator-quickstep git commit: Get number of active queries (total and by priority level)
Date Fri, 24 Jun 2016 16:41:04 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/scheduler++ 46fa5557e -> 83421a481


Get number of active queries (total and by priority level)

- Unit tests to check the feature.


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

Branch: refs/heads/scheduler++
Commit: e11588e4662f3f3a6f88908e869994deff489aa4
Parents: 46fa555
Author: Harshad Deshmukh <hbdeshmukh@apache.org>
Authored: Fri Jun 24 10:42:56 2016 -0500
Committer: Harshad Deshmukh <hbdeshmukh@apache.org>
Committed: Fri Jun 24 10:42:56 2016 -0500

----------------------------------------------------------------------
 query_execution/Learner.hpp                | 16 +++++++-
 query_execution/tests/Learner_unittest.cpp | 54 ++++++++++++++++++++-----
 2 files changed, 58 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/e11588e4/query_execution/Learner.hpp
----------------------------------------------------------------------
diff --git a/query_execution/Learner.hpp b/query_execution/Learner.hpp
index 9d51877..fb0e4cb 100644
--- a/query_execution/Learner.hpp
+++ b/query_execution/Learner.hpp
@@ -102,10 +102,24 @@ class Learner {
   // at this point.
   void updateProbabilitiesOfAllPriorityLevels(const std::size_t priority_level);
 
-  inline const std::size_t hasActiveQueries() const {
+  inline const bool hasActiveQueries() const {
     return !query_id_to_priority_lookup_.empty();
   }
 
+  inline const std::size_t getNumActiveQueriesInPriorityLevel(
+      const std::size_t priority_level) const {
+    const auto it = execution_stats_.find(priority_level);
+    if (it != execution_stats_.end()) {
+      return it->second.size();
+    } else {
+      return 0;
+    }
+  }
+
+  inline const std::size_t getTotalNumActiveQueries() const {
+    return query_id_to_priority_lookup_.size();
+  }
+
  private:
   /**
    * @brief Initialize the default probabilities for the queries.

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/e11588e4/query_execution/tests/Learner_unittest.cpp
----------------------------------------------------------------------
diff --git a/query_execution/tests/Learner_unittest.cpp b/query_execution/tests/Learner_unittest.cpp
index cab241a..74353f0 100644
--- a/query_execution/tests/Learner_unittest.cpp
+++ b/query_execution/tests/Learner_unittest.cpp
@@ -24,32 +24,64 @@
 
 namespace quickstep {
 
-TEST(LearnerTest, AddQueryTest) {
+TEST(LearnerTest, AddAndRemoveQueryTest) {
   Learner learner;
   std::unique_ptr<QueryHandle> handle;
-  handle.reset(new QueryHandle(1, 1));
+  const std::size_t kPriorityLevel1 = 1;
+  handle.reset(new QueryHandle(1, kPriorityLevel1));
 
   EXPECT_FALSE(learner.hasActiveQueries());
   learner.addQuery(*handle);
+  EXPECT_EQ(1u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel1));
   EXPECT_TRUE(learner.hasActiveQueries());
+  learner.removeQuery(handle->query_id());
+  EXPECT_EQ(0u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(0u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel1));
+  EXPECT_FALSE(learner.hasActiveQueries());
+
+  const std::size_t kPriorityLevel2 = 1;
+  handle.reset(new QueryHandle(1, kPriorityLevel2));
+  learner.addQuery(*handle);
+  EXPECT_EQ(1u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel2));
+  EXPECT_TRUE(learner.hasActiveQueries());
+  learner.removeQuery(handle->query_id());
+  EXPECT_EQ(0u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(0u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel2));
+  EXPECT_FALSE(learner.hasActiveQueries());
 }
 
-TEST(LearnerTest, RemoveQueryTest) {
+TEST(LearnerTest, MultipleQueriesSamePriorityAddRemoveTest) {
   Learner learner;
-  std::unique_ptr<QueryHandle> handle;
-  handle.reset(new QueryHandle(1, 1));
+  std::unique_ptr<QueryHandle> handle1, handle2;
+  const std::size_t kPriorityLevel = 1;
+  handle1.reset(new QueryHandle(1, kPriorityLevel));
+  handle2.reset(new QueryHandle(2, kPriorityLevel));
 
   EXPECT_FALSE(learner.hasActiveQueries());
-  learner.addQuery(*handle);
+  EXPECT_EQ(0u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(0u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
+
+  learner.addQuery(*handle1);
   EXPECT_TRUE(learner.hasActiveQueries());
-  learner.removeQuery(handle->query_id());
-  EXPECT_FALSE(learner.hasActiveQueries());
+  EXPECT_EQ(1u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
+  learner.addQuery(*handle2);
+  EXPECT_TRUE(learner.hasActiveQueries());
+  EXPECT_EQ(2u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(2u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
 
-  handle.reset(new QueryHandle(2, 1));
-  learner.addQuery(*handle);
+  learner.removeQuery(handle1->query_id());
   EXPECT_TRUE(learner.hasActiveQueries());
-  learner.removeQuery(handle->query_id());
+  EXPECT_EQ(1u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
+
+  learner.removeQuery(handle2->query_id());
+
   EXPECT_FALSE(learner.hasActiveQueries());
+  EXPECT_EQ(0u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(0u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
 }
 
 }  // namespace quickstep


Mime
View raw message