Uses cdsstress library
authorPeizhao Ou <peizhaoo@uci.edu>
Fri, 9 Feb 2018 21:31:25 +0000 (13:31 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Fri, 9 Feb 2018 21:31:25 +0000 (13:31 -0800)
test/CMakeLists.txt
test/junction_parallel_driver.cpp

index fe8a11e6f0cdc67b05e2031e8ba0470d6737a5dc..adb76de9bafce6fb10ec5570a9ccd28e929ae141 100644 (file)
@@ -3,7 +3,14 @@ cmake_minimum_required(VERSION 2.8.5)
 set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Build configs")
 
 include_directories(
 set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Build configs")
 
 include_directories(
-    /scratch/googletest/googletest/include/
+    /scratch/googletest/googletest/include
+    /scratch/benchmarks/libcds/test/include
+    /scratch/benchmarks/libcds
+)
+
+link_directories(
+    /scratch/benchmarks/libcds/build/bin
+    /scratch/googletest/googletest
 )
 
 set(SEQUENTIAL_DRIVER stress-sequential-junction)
 )
 
 set(SEQUENTIAL_DRIVER stress-sequential-junction)
@@ -12,10 +19,10 @@ set(PARALLEL_DRIVER stress-parallel-junction)
 set(JUNCTION_LIB
   junction
   turf
 set(JUNCTION_LIB
   junction
   turf
-  # AArch64 lib
-  /scratch/googletest/googletest/libgtest.a
-  # x86 lib
-  #/scratch/googletest/libgtest.a
+  # It's fine to link the lib compiled from original clang because we are only
+  # using the config parsing functionality.
+  stress-framework
+  gtest
 )
 
 add_executable(${SEQUENTIAL_DRIVER} junction_sequential_driver.cpp)
 )
 
 add_executable(${SEQUENTIAL_DRIVER} junction_sequential_driver.cpp)
index b9f5d8f07e82f094b007f3b540ea6508dc128a33..b6f74f6fb2213d327ae68250ae7ba58e93778290 100644 (file)
@@ -3,38 +3,41 @@
 #include <junction/ConcurrentMap_Leapfrog.h>
 #include <junction/ConcurrentMap_Linear.h>
 
 #include <junction/ConcurrentMap_Leapfrog.h>
 #include <junction/ConcurrentMap_Linear.h>
 
-#include <gtest/gtest.h>
+#include <cds_test/stress_test.h>
+#include <cds_test/stress_test_util.h>
 
 #include <algorithm>
 
 #include <algorithm>
+#include <iostream>
 #include <memory>
 #include <random>
 #include <memory>
 #include <random>
+#include <thread>
 
 namespace junction_test {
 
 
 namespace junction_test {
 
-class JunctionMapInsDelFindTest_Parallel : public ::testing::Test {
+class JunctionMapInsDelFindTest_Parallel : public cds_test::stress_fixture {
 protected:
   typedef junction::ConcurrentMap_Grampa<size_t, size_t> GrampaMap;
   typedef junction::ConcurrentMap_Linear<size_t, size_t> LinearMap;
   typedef junction::ConcurrentMap_Leapfrog<size_t, size_t> LeapfrogMap;
   typedef junction::ConcurrentMap_Crude<size_t, size_t> CrudeMap;
 
 protected:
   typedef junction::ConcurrentMap_Grampa<size_t, size_t> GrampaMap;
   typedef junction::ConcurrentMap_Linear<size_t, size_t> LinearMap;
   typedef junction::ConcurrentMap_Leapfrog<size_t, size_t> LeapfrogMap;
   typedef junction::ConcurrentMap_Crude<size_t, size_t> CrudeMap;
 
-  static const unsigned s_nInsertPercentage = 5;
-  static const unsigned s_nDeletePercentage = 5;
-
-  // Run GC after "kGCFrequency" operations.
-  const size_t kGCFrequency = 1500;
-  const size_t kMapSize = 20000;
+  static unsigned s_nInsertPercentage;
+  static unsigned s_nDeletePercentage;
+  static size_t s_nGCFrequency; // Run GC after "s_nGCFrequency" operations.
+  static size_t s_nThreadCount;
+  static size_t s_nMapKeyRange;
+  static size_t s_nCrudeMapCapacity;
 
   enum actions { do_find, do_insert, do_delete };
   static const unsigned int kShuffleSize = 100;
   static actions s_arrShuffle[kShuffleSize];
 
 
   enum actions { do_find, do_insert, do_delete };
   static const unsigned int kShuffleSize = 100;
   static actions s_arrShuffle[kShuffleSize];
 
-  const size_t kCrudePassCount = 400000;
-  const size_t kGrampaPassCount = 60000;
-  const size_t kLinearPassCount = 70000;
-  const size_t kLeapfrogPassCount = 75000;
+  static size_t s_nCrudePassCount;
+  static size_t s_nGrampaPassCount;
+  static size_t s_nLinearPassCount;
+  static size_t s_nLeapfrogPassCount;
 
 
-  static void SetUpTestCase() {
+  static void InitShuffleArray() {
     // Build an array of shuffled actions.
     EXPECT_LE(s_nInsertPercentage + s_nDeletePercentage, 100);
     actions* pFirst = s_arrShuffle;
     // Build an array of shuffled actions.
     EXPECT_LE(s_nInsertPercentage + s_nDeletePercentage, 100);
     actions* pFirst = s_arrShuffle;
@@ -53,10 +56,26 @@ protected:
     std::shuffle(s_arrShuffle, pLast, g);
   }
 
     std::shuffle(s_arrShuffle, pLast, g);
   }
 
+  static void SetUpTestCase() {
+    InitShuffleArray();
+    const cds_test::config& cfg = get_config("ParallelJunction");
+    GetConfigNonZeroExpected(InsertPercentage, 5);
+    GetConfigNonZeroExpected(DeletePercentage, 5);
+    GetConfigNonZeroExpected(ThreadCount, 4);
+    GetConfigNonZeroExpected(MapKeyRange, 20000);
+    GetConfigNonZeroExpected(CrudeMapCapacity, s_nMapKeyRange * 64);
+    GetConfigNonZeroExpected(GCFrequency, 1500);
+    GetConfigNonZeroExpected(CrudePassCount, 1500000000);
+    GetConfigNonZeroExpected(GrampaPassCount, 650000000);
+    GetConfigNonZeroExpected(LinearPassCount, 900000000);
+    GetConfigNonZeroExpected(LeapfrogPassCount, 850000000);
+  }
+
   template <typename Map, typename Key, typename Value>
   static bool map_insert(Map* map, Key key, Value value) {
     auto iter = map->insertOrFind(key);
   template <typename Map, typename Key, typename Value>
   static bool map_insert(Map* map, Key key, Value value) {
     auto iter = map->insertOrFind(key);
-    if (!iter.getValue()) {
+    if (!iter.getValue() || iter.getValue() != value) {
+      // Insert/update the <key,value> pair
       iter.assignValue(value);
       return true;
     } else {
       iter.assignValue(value);
       return true;
     } else {
@@ -88,7 +107,8 @@ protected:
   // Specialization for CrudeMap
   template <typename Key, typename Value>
   static bool map_insert(CrudeMap* map, Key key, Value value) {
   // Specialization for CrudeMap
   template <typename Key, typename Value>
   static bool map_insert(CrudeMap* map, Key key, Value value) {
-    if (!map->get(key)) {
+    auto old_val = map->get(key);
+    if (!old_val || old_val != value) {
       map->assign(key, value);
       return true;
     } else {
       map->assign(key, value);
       return true;
     } else {
@@ -109,12 +129,12 @@ protected:
     return map->get(key) != ((Key)0);
   }
 
     return map->get(key) != ((Key)0);
   }
 
-  template <typename Map> void run_test(Map* map, size_t pass_count) {
+  template <typename Map> static void run_test(Map* map, size_t pass_count) {
     auto qsbrContext = junction::DefaultQSBR.createContext();
 
     std::random_device rd;
     std::mt19937 gen(rd());
     auto qsbrContext = junction::DefaultQSBR.createContext();
 
     std::random_device rd;
     std::mt19937 gen(rd());
-    std::uniform_int_distribution<size_t> dis(kMapSize, 2 * kMapSize);
+    std::uniform_int_distribution<size_t> dis(2, s_nMapKeyRange);
 
     unsigned action_index = 0;
     size_t nInsertedNum = 0;
 
     unsigned action_index = 0;
     size_t nInsertedNum = 0;
@@ -122,35 +142,34 @@ protected:
     size_t nOperations = 0;
 
     for (size_t count = 0; count < pass_count; count++) {
     size_t nOperations = 0;
 
     for (size_t count = 0; count < pass_count; count++) {
-      for (size_t i = 0; i < kMapSize; ++i) {
-        // The number to operate on the map.
-        size_t n = dis(gen);
-        switch (s_arrShuffle[action_index]) {
-          case do_insert: {
-            if (map_insert(map, n, n)) {
-              nInsertedNum++;
-            }
-            break;
-          }
-          case do_delete: {
-            map_delete(map, n);
-            break;
+      // The number to operate on the map.
+      size_t key = dis(gen);
+      switch (s_arrShuffle[action_index]) {
+        case do_insert: {
+          size_t val = dis(gen);
+          if (map_insert(map, key, val)) {
+            nInsertedNum++;
           }
           }
-          case do_find: {
-            if (map_find(map, n)) {
-              ++nFindSuccess;
-            }
-            break;
-          }
-          default: { break; }
+          break;
         }
         }
-        if (++action_index >= kShuffleSize) {
-          action_index = 0;
+        case do_delete: {
+          map_delete(map, key);
+          break;
         }
         }
-        if (++nOperations > kGCFrequency) {
-          junction::DefaultQSBR.update(qsbrContext);
-          nOperations = 0;
+        case do_find: {
+          if (map_find(map, key)) {
+            ++nFindSuccess;
+          }
+          break;
         }
         }
+        default: { break; }
+      }
+      if (++action_index >= kShuffleSize) {
+        action_index = 0;
+      }
+      if (++nOperations > s_nGCFrequency) {
+        junction::DefaultQSBR.update(qsbrContext);
+        nOperations = 0;
       }
     }
     junction::DefaultQSBR.update(qsbrContext);
       }
     }
     junction::DefaultQSBR.update(qsbrContext);
@@ -158,35 +177,55 @@ protected:
   }
 };
 
   }
 };
 
-const unsigned JunctionMapInsDelFindTest_Parallel::s_nInsertPercentage;
-const unsigned JunctionMapInsDelFindTest_Parallel::s_nDeletePercentage;
+size_t JunctionMapInsDelFindTest_Parallel::s_nThreadCount;
+size_t JunctionMapInsDelFindTest_Parallel::s_nMapKeyRange;
+size_t JunctionMapInsDelFindTest_Parallel::s_nCrudeMapCapacity;
+size_t JunctionMapInsDelFindTest_Parallel::s_nGCFrequency;
+unsigned JunctionMapInsDelFindTest_Parallel::s_nInsertPercentage;
+unsigned JunctionMapInsDelFindTest_Parallel::s_nDeletePercentage;
 const unsigned int JunctionMapInsDelFindTest_Parallel::kShuffleSize;
 JunctionMapInsDelFindTest_Parallel::actions JunctionMapInsDelFindTest_Parallel::
     s_arrShuffle[JunctionMapInsDelFindTest_Parallel::kShuffleSize];
 const unsigned int JunctionMapInsDelFindTest_Parallel::kShuffleSize;
 JunctionMapInsDelFindTest_Parallel::actions JunctionMapInsDelFindTest_Parallel::
     s_arrShuffle[JunctionMapInsDelFindTest_Parallel::kShuffleSize];
+size_t JunctionMapInsDelFindTest_Parallel::s_nCrudePassCount;
+size_t JunctionMapInsDelFindTest_Parallel::s_nGrampaPassCount;
+size_t JunctionMapInsDelFindTest_Parallel::s_nLinearPassCount;
+size_t JunctionMapInsDelFindTest_Parallel::s_nLeapfrogPassCount;
+
+#define JunctionThreading(map_type, pass_count)                                \
+  std::unique_ptr<std::thread[]> threads(new std::thread[s_nThreadCount]);       \
+  for (size_t i = 0; i < s_nThreadCount; i++) {                                  \
+    threads[i] = std::thread(run_test<map_type>, map.get(), pass_count);       \
+  }                                                                            \
+  for (size_t i = 0; i < s_nThreadCount; i++) {                                  \
+    threads[i].join();                                                         \
+  }
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapCrude) {
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapCrude) {
-  std::unique_ptr<CrudeMap> map(new CrudeMap(kMapSize * 32));
-  run_test(map.get(), kCrudePassCount);
+  std::unique_ptr<CrudeMap> map(new CrudeMap(s_nCrudeMapCapacity));
+  JunctionThreading(CrudeMap, s_nCrudePassCount);
 }
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLeapfrog) {
   std::unique_ptr<LeapfrogMap> map(new LeapfrogMap());
 }
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLeapfrog) {
   std::unique_ptr<LeapfrogMap> map(new LeapfrogMap());
-  run_test(map.get(), kLeapfrogPassCount);
+  JunctionThreading(LeapfrogMap, s_nLeapfrogPassCount);
 }
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLinear) {
   std::unique_ptr<LinearMap> map(new LinearMap());
 }
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLinear) {
   std::unique_ptr<LinearMap> map(new LinearMap());
-  run_test(map.get(), kLinearPassCount);
+  JunctionThreading(LinearMap, s_nLinearPassCount);
 }
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapGrampa) {
   std::unique_ptr<GrampaMap> map(new GrampaMap());
 }
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapGrampa) {
   std::unique_ptr<GrampaMap> map(new GrampaMap());
-  run_test(map.get(), kGrampaPassCount);
+  JunctionThreading(GrampaMap, s_nGrampaPassCount);
 }
 
 } // namespace junction_test
 
 int main(int argc, char** argv) {
 }
 
 } // namespace junction_test
 
 int main(int argc, char** argv) {
+  // Read test config file
+  cds_test::init_config(argc, argv);
+
   // Init Google test
   ::testing::InitGoogleTest(&argc, argv);
   int result = RUN_ALL_TESTS();
   // Init Google test
   ::testing::InitGoogleTest(&argc, argv);
   int result = RUN_ALL_TESTS();