Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Perf between PersistentSkipListMap vs PersistentSkipListMap2 #18

@JerryYangSH

Description

@JerryYangSH

I tested the latency PersistentSkipListMap and PersistentSkipListMap2. It looks PersistentSkipListMap is doing a better job than PersistentSkipListMap2 regarding the avg latency. What makes this difference? Which one is preferred?

Testing benchmark PersistentSkipListMap******
[Key Count 1000] avg lat:
DELETE : 151 (us)
CREATE : 158 (us)
GET : 74 (us)
UPDATE : 120 (us)
[Key Count 10000] avg lat:
DELETE : 71 (us)
CREATE : 130 (us)
GET : 143 (us)
UPDATE : 82 (us)
[Key Count 50000] avg lat:
DELETE : 102 (us)
CREATE : 117 (us)
GET : 45 (us)
UPDATE : 126 (us)
Testing benchmark PersistentSkipListMap2******
[Key Count 1000] avg lat:
DELETE : 201 (us)
CREATE : 214 (us)
GET : 64 (us)
UPDATE : 152 (us)
[Key Count 10000] avg lat:
DELETE : 122 (us)
CREATE : 198 (us)
GET : 68 (us)
UPDATE : 163 (us)
My Test code is below:


jerry@u19:~/opensources/pcj$ git diff
diff --git a/src/test/java/tests/PersistentSkipListMapTest.java b/src/test/java/tests/PersistentSkipListMapTest.java
index cfdbc4d..1782295 100644
--- a/src/test/java/tests/PersistentSkipListMapTest.java
+++ b/src/test/java/tests/PersistentSkipListMapTest.java
@@ -43,6 +43,8 @@ static boolean verbose = false;
         System.out.println("****************PersistentSkipListMap Tests************");
         return testInsertion() &&
         testRemoval() &&
+        testBenchmark(getPersistentSkipListMap()) &&
+        testBenchmark(getPersistentSkipListMap2()) &&
         testIteration() &&
         testSubMap() &&
         testPutAll() &&
@@ -64,6 +66,26 @@ static boolean verbose = false;
                return map;
        }

+    private static PersistentSkipListMap<PersistentString, PersistentString> getPersistentSkipListMap() {
+        String id = threadSafeId("tests.PersistentSkipListMap");
+        PersistentSkipListMap<PersistentString, PersistentString> map = ObjectDirectory.get(id,PersistentSkipListMap.class);
+        if(map == null) {
+            map = new PersistentSkipListMap<>();
+            ObjectDirectory.put(id, map);
+        }
+        return map;
+    }
+
+    private static PersistentSkipListMap2<PersistentString, PersistentString> getPersistentSkipListMap2() {
+        String id = threadSafeId("tests.PersistentSkipListMap2");
+        PersistentSkipListMap2<PersistentString, PersistentString> map = ObjectDirectory.get(id,PersistentSkipListMap2.class);
+        if(map == null) {
+            map = new PersistentSkipListMap2<>();
+            ObjectDirectory.put(id, map);
+        }
+        return map;
+    }
+
     @SuppressWarnings("unchecked")
     public static boolean testInsertion() {
         if (verbose) System.out.println("****************Testing insertion**********************");
@@ -93,6 +115,82 @@ static boolean verbose = false;
         return true;
     }

+    @SuppressWarnings("unchecked")
+    public static boolean testBenchmark(PersistentSortedMap<PersistentString, PersistentString> map) {
+        System.out.println(String.format("****************Testing benchmark %s**********************", map.getClass().getSimpleName()));
+
+        assert (map != null);
+        map.clear();
+        assert(map.size() == 0);
+
+        final int KeySize = 128;
+        final int ValueSize = 1024;
+        StringBuilder keyPrefixBuilder = new StringBuilder();
+        for (int i = 0; i < KeySize; i++) {
+            keyPrefixBuilder.append('~');
+        }
+        String keyPrefix = keyPrefixBuilder.toString();
+        StringBuilder valuePrefixBuilder = new StringBuilder();
+        for (int i = 0; i < ValueSize; i++) {
+            valuePrefixBuilder.append('&');
+        }
+        String valuePrefix = valuePrefixBuilder.toString();
+
+        final int[] LoopCounts = new int[] {1000, 10000, 50000};
+        for (int LoopCount : LoopCounts) {
+            System.out.println(String.format("[Key Count %6d] avg lat:", LoopCount));
+            map.clear();
+            assert(map.size() == 0);
+            Map<String, Long> latencies = new HashMap<>();
+
+            // CREATE:
+            long start = System.nanoTime();
+            for (int l = 0; l < LoopCount; l++) {
+                PersistentString key = new PersistentString(keyPrefix + l);
+                PersistentString val = new PersistentString(valuePrefix + l);
+                PersistentString out = map.put(key, val);
+                if (out != null) {
+                    System.out.println(String.format("CREATING key %s failed, out = %s", keyPrefix + l, out.toString()));
+                }
+                assert(out == null);
+            }
+            latencies.put("CREATE", (System.nanoTime() - start) / LoopCount);
+
+            // GET
+            start = System.nanoTime();
+            for (int l = 0; l < LoopCount; l++) {
+                PersistentString key = new PersistentString(keyPrefix + l);
+                assert(map.get(key).toString().equals(valuePrefix + l));
+            }
+            latencies.put("GET", (System.nanoTime() - start) / LoopCount);
+
+            // UPDATE
+            start = System.nanoTime();
+            for (int l = 0; l < LoopCount; l++) {
+                PersistentString key = new PersistentString(keyPrefix + l);
+                PersistentString val = new PersistentString(valuePrefix);
+                PersistentString out = map.put(key, val);
+                assert(out.toString().equals(valuePrefix + l));
+            }
+            latencies.put("UPDATE", (System.nanoTime() - start) / LoopCount);
+
+            // DELETE
+            start = System.nanoTime();
+            for (int l = 0; l < LoopCount; l++) {
+                PersistentString key = new PersistentString(keyPrefix + l);
+                PersistentString out = map.remove(key);
+            }
+            latencies.put("DELETE", (System.nanoTime() - start) / LoopCount);
+
+            for (Map.Entry<String, Long> lat : latencies.entrySet()) {
+                System.out.println(String.format("\t%8s : %8d (us)", lat.getKey(), lat.getValue() / 1000));
+            }
+        }
+
+        map.clear();
+        return true;
+    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions