zookeeper-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] hanm commented on a change in pull request #989: ZOOKEEPER-3430: Observability improvement: provide top N read / write path queries.
Date Sat, 27 Jul 2019 04:58:30 GMT
hanm commented on a change in pull request #989: ZOOKEEPER-3430: Observability improvement:
provide top N read / write path queries.
URL: https://github.com/apache/zookeeper/pull/989#discussion_r307953246
 
 

 ##########
 File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/util/RequestPathMetricsCollectorTest.java
 ##########
 @@ -0,0 +1,457 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.server.util;
+
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.apache.zookeeper.ZooDefs.OpCode.create;
+import static org.apache.zookeeper.ZooDefs.OpCode.create2;
+import static org.apache.zookeeper.ZooDefs.OpCode.delete;
+import static org.apache.zookeeper.ZooDefs.OpCode.exists;
+import static org.apache.zookeeper.ZooDefs.OpCode.getChildren;
+import static org.apache.zookeeper.ZooDefs.OpCode.getChildren2;
+import static org.apache.zookeeper.ZooDefs.OpCode.getData;
+import static org.apache.zookeeper.ZooDefs.OpCode.setData;
+
+public class RequestPathMetricsCollectorTest {
+    public RequestPathMetricsCollectorTest() {
+        //tune the request metrics receiver parameters
+        System.setProperty("zookeeper.pathStats.slotCapacity", "60");
+        System.setProperty("zookeeper.pathStats.slotDuration", "1");
+        System.setProperty("zookeeper.pathStats.maxDepth", "6");
+        System.setProperty("zookeeper.pathStats.sampleRate", "1.0");
+    }
+
+    @Test
+    public void testTrimPath() {
+        //normal cases
+        String trimedPath = RequestPathMetricsCollector.trimPathDepth("/p1/p2/p3", 1);
+        Assert.assertTrue(trimedPath.equalsIgnoreCase("/p1"));
+        trimedPath = RequestPathMetricsCollector.trimPathDepth("/p1/p2/p3", 2);
+        Assert.assertTrue(trimedPath.equalsIgnoreCase("/p1/p2"));
+        trimedPath = RequestPathMetricsCollector.trimPathDepth("/p1/p2/p3", 3);
+        Assert.assertTrue(trimedPath.equalsIgnoreCase("/p1/p2/p3"));
+        trimedPath = RequestPathMetricsCollector.trimPathDepth("/p1/p2/p3", 4);
+        Assert.assertTrue(trimedPath.equalsIgnoreCase("/p1/p2/p3"));
+        //some extra symbols
+        trimedPath = RequestPathMetricsCollector.trimPathDepth("//p1 next/p2.index/p3:next",
+            3);
+        Assert.assertTrue(trimedPath.equalsIgnoreCase("/p1 next/p2.index/p3:next"));
+        trimedPath = RequestPathMetricsCollector.trimPathDepth("//p1 next/p2.index/p3:next",
+            2);
+        Assert.assertTrue(trimedPath.equalsIgnoreCase("/p1 next/p2.index"));
+        trimedPath = RequestPathMetricsCollector.trimPathDepth("//p1 next/p2.index/p3:next",
+            6);
+        Assert.assertTrue(trimedPath.equalsIgnoreCase("/p1 next/p2.index/p3:next"));
+    }
+
+    @Test
+    public void testQueueMapReduce() throws InterruptedException {
+        RequestPathMetricsCollector requestPathMetricsCollector = new RequestPathMetricsCollector();
+        RequestPathMetricsCollector.PathStatsQueue pathStatsQueue =
+            requestPathMetricsCollector.new PathStatsQueue(create2);
+        Thread path7 = new Thread(() -> {
+            for (int i = 0; i < 1000000; i++) {
+                pathStatsQueue.registerRequest("/path1/path2/path3/path4/path5/path6/path7"
+
+                    "_" + i);
+            }
+        });
+        path7.start();
+        Thread path6 = new Thread(() -> {
+            pathStatsQueue.registerRequest("/path1/path2/path3/path4/path5/path6");
+            for(int i = 1; i < 100000; i++) {
+                pathStatsQueue.registerRequest("/path1/path2/path3/path4/path5/path6"+"_"+i);
+            }
+        });
+        path6.start();
+        for(int i = 0; i < 1; i++) {
+            pathStatsQueue.registerRequest("/path1");
+        }
+        for(int i = 0; i < 10; i++) {
+            pathStatsQueue.registerRequest("/path1/path2"+"_"+i);
+        }
+        for(int i = 0; i < 100; i++) {
+            pathStatsQueue.registerRequest("/path1/path2/path3"+"_"+i);
+        }
+        for(int i = 0; i < 1000; i++) {
+            pathStatsQueue.registerRequest("/path1/path2/path3/path4"+"_"+i);
+        }
+        for(int i = 0; i < 10000; i++) {
+            pathStatsQueue.registerRequest("/path1/path2/path3/path4/path5"+"_"+i);
+        }
+        path6.join();
+        path7.join();
+        Map<String, Integer> newSlot = pathStatsQueue.mapReducePaths(1,
+            pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.size() == 1);
+        Assert.assertTrue(newSlot.get("/path1").compareTo(1111111) == 0);
+        //cut up to 2
+        newSlot = pathStatsQueue.mapReducePaths(2, pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.size() == 12);
+        Assert.assertTrue(newSlot.get("/path1").compareTo(1) == 0);
+        Assert.assertTrue(newSlot.get("/path1/path2").compareTo(1111100) == 0);
+        //cut up to 3
+        newSlot = pathStatsQueue.mapReducePaths(3, pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.size() == 112);
+        Assert.assertTrue(newSlot.get("/path1").compareTo(1) == 0);
+        Assert.assertTrue(newSlot.get("/path1/path2/path3").compareTo(1111000) == 0);
+        //cut up to 4
+        newSlot = pathStatsQueue.mapReducePaths(4, pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.size() == 1112);
+        Assert.assertTrue(newSlot.get("/path1/path2/path3/path4").compareTo(1110000) == 0);
+        //cut up to 5
+        newSlot = pathStatsQueue.mapReducePaths(5, pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.size() == 11112);
+        Assert.assertTrue(newSlot.get("/path1/path2/path3/path4/path5").compareTo(1100000)
== 0);
+        //cut up to 6
+        newSlot = pathStatsQueue.mapReducePaths(6, pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.size() == 111111);
+        Assert.assertTrue(newSlot.get("/path1/path2/path3/path4/path5/path6").compareTo(1000001)
== 0);
+        //cut up to 7
+        newSlot = pathStatsQueue.mapReducePaths(7, pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.size() == 1111111);
+    }
+
+    @Test
+    public void testCollectEmptyStats() throws InterruptedException {
+        RequestPathMetricsCollector requestPathMetricsCollector = new RequestPathMetricsCollector();
+        RequestPathMetricsCollector.PathStatsQueue pathStatsQueue =
+            requestPathMetricsCollector.new PathStatsQueue(getChildren);
+        Thread.sleep(5000);
+        Map<String, Integer> newSlot = pathStatsQueue.mapReducePaths(3,
+            pathStatsQueue.getCurrentSlot());
+        Assert.assertTrue(newSlot.isEmpty());
+        pathStatsQueue.start();
+        Thread.sleep(15000);
+        newSlot = pathStatsQueue.collectStats(1);
+        Assert.assertTrue(newSlot.size() == 0);
+        newSlot = pathStatsQueue.collectStats(2);
+        Assert.assertTrue(newSlot.size() == 0);
+        newSlot = pathStatsQueue.collectStats(5);
+        Assert.assertTrue(newSlot.size() == 0);
+    }
+    
+    @Ignore
+    @Test
+    public void testCollectStats() throws InterruptedException {
+        RequestPathMetricsCollector requestPathMetricsCollector =
+            new RequestPathMetricsCollector(true);
+        RequestPathMetricsCollector.PathStatsQueue pathStatsQueue =
+            requestPathMetricsCollector.new PathStatsQueue(getChildren);
+        pathStatsQueue.start();
+        Thread path7 = new Thread(() -> {
+            for(int i = 0; i < 10; i++) {
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+                for (int j = 0; j < 100000; j++) {
+                    pathStatsQueue.registerRequest("/path1/path2/path3/path4/path5/path6/path7"
+                        + "_" + i + "_" + j);
+                }
+            }
+        });
+        path7.start();
+        Thread path6 = new Thread(() -> {
+            pathStatsQueue.registerRequest("/path1/path2/path3/path4/path5/path6");
+            for(int i = 0; i < 10; i++) {
+                try {
+                    Thread.sleep(1000);
 
 Review comment:
   reduced to 5 sec.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message