zookeeper-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] eolivelli commented on a change in pull request #989: ZOOKEEPER-3430: Observability improvement: provide top N read / write path queries.
Date Fri, 26 Jul 2019 21:52:18 GMT
eolivelli 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_r307920886
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/util/RequestPathMetricsCollector.java
 ##########
 @@ -0,0 +1,385 @@
+/**
+ * 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.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.server.Request;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.zookeeper.ZooDefs.OpCode.checkWatches;
+import static org.apache.zookeeper.ZooDefs.OpCode.create;
+import static org.apache.zookeeper.ZooDefs.OpCode.create2;
+import static org.apache.zookeeper.ZooDefs.OpCode.createContainer;
+import static org.apache.zookeeper.ZooDefs.OpCode.delete;
+import static org.apache.zookeeper.ZooDefs.OpCode.deleteContainer;
+import static org.apache.zookeeper.ZooDefs.OpCode.exists;
+import static org.apache.zookeeper.ZooDefs.OpCode.getACL;
+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.removeWatches;
+import static org.apache.zookeeper.ZooDefs.OpCode.setACL;
+import static org.apache.zookeeper.ZooDefs.OpCode.setData;
+import static org.apache.zookeeper.ZooDefs.OpCode.sync;
+
+/**
+ * This class holds the requests path ( up till a certain depth) stats per request type
+ */
+public class RequestPathMetricsCollector {
+    private static final Logger LOG = LoggerFactory.getLogger(RequestPathMetricsCollector.class);
+    // How many seconds does each slot represent, default is 15 seconds.
+    private final int REQUEST_STATS_SLOT_DURATION;
+    // How many slots we keep, default is 60 so it's 15 minutes total history.
+    private final int REQUEST_STATS_SLOT_CAPACITY;
+    // How far down the path we keep, default is 6.
+    private final int REQUEST_PREPROCESS_PATH_DEPTH;
+    // Sample rate, default is 0.1 (10%).
+    private final float REQUEST_PREPROCESS_SAMPLE_RATE;
+    private final long COLLECTOR_INITIAL_DELAY;
+    private final long COLLECTOR_DELAY;
+    private final int REQUEST_PREPROCESS_TOPPATH_MAX;
+    private final boolean disabled;
+
+    public static final String PATH_STATS_SLOT_CAPACITY = "zookeeper.pathStats.slotCapacity";
+    public static final String PATH_STATS_SLOT_DURATION = "zookeeper.pathStats.slotDuration";
+    public static final String PATH_STATS_MAX_DEPTH = "zookeeper.pathStats.maxDepth";
+    public static final String PATH_STATS_SAMPLE_RATE = "zookeeper.pathStats.sampleRate";
+    public static final String PATH_STATS_COLLECTOR_INITIAL_DELAY = "zookeeper.pathStats.initialDelay";
+    public static final String PATH_STATS_COLLECTOR_DELAY = "zookeeper.pathStats.delay";
+    public static final String PATH_STATS_TOP_PATH_MAX = "zookeeper.pathStats.topPathMax";
+    public static final String PATH_STATS_DISABLE = "zookeeper.pathStats.disable";
+
+    private final Map<String, PathStatsQueue> immutableRequestsMap;
+    private final Random sampler;
+    private final ScheduledThreadPoolExecutor scheduledExecutor;
+    private final boolean accurateMode;
+
+    public RequestPathMetricsCollector() {
+        this(false);
+    }
+    
+    public RequestPathMetricsCollector(boolean accurateMode) {
+        final HashMap<String, PathStatsQueue> requestsMap = new HashMap<>();
+        this.sampler = new Random(System.currentTimeMillis());
+        this.accurateMode = accurateMode;
+
+        REQUEST_PREPROCESS_TOPPATH_MAX = Integer.getInteger(PATH_STATS_TOP_PATH_MAX, 20);
+        REQUEST_STATS_SLOT_DURATION = Integer.getInteger(PATH_STATS_SLOT_DURATION, 15);
+        REQUEST_STATS_SLOT_CAPACITY = Integer.getInteger(PATH_STATS_SLOT_CAPACITY, 60);
+        REQUEST_PREPROCESS_PATH_DEPTH = Integer.getInteger(PATH_STATS_MAX_DEPTH, 6);
+        REQUEST_PREPROCESS_SAMPLE_RATE = Float.parseFloat(
+            System.getProperty(PATH_STATS_SAMPLE_RATE, "0.1"));
+        COLLECTOR_INITIAL_DELAY = Long.getLong(PATH_STATS_COLLECTOR_INITIAL_DELAY, 5);
+        COLLECTOR_DELAY = Long.getLong(PATH_STATS_COLLECTOR_DELAY, 5);
+        disabled = Boolean.getBoolean(PATH_STATS_DISABLE);
+
+        LOG.info("{} = {}", PATH_STATS_SLOT_CAPACITY, REQUEST_STATS_SLOT_CAPACITY);
+        LOG.info("{} = {}", PATH_STATS_SLOT_DURATION, REQUEST_STATS_SLOT_DURATION);
+        LOG.info("{} = {}", PATH_STATS_MAX_DEPTH, REQUEST_PREPROCESS_PATH_DEPTH);
+        LOG.info("{} = {}", PATH_STATS_COLLECTOR_INITIAL_DELAY, COLLECTOR_INITIAL_DELAY);
+        LOG.info("{} = {}", PATH_STATS_COLLECTOR_DELAY, COLLECTOR_DELAY);
+        LOG.info("{} = {}", PATH_STATS_DISABLE, disabled);
+
+        this.scheduledExecutor = (ScheduledThreadPoolExecutor) Executors
+            .newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
+        scheduledExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
+        scheduledExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
+        requestsMap.put(Request.op2String(create), new PathStatsQueue(create));
+        requestsMap.put(Request.op2String(create2), new PathStatsQueue(create2));
+        requestsMap.put(Request.op2String(createContainer), new PathStatsQueue(createContainer));
+        requestsMap.put(Request.op2String(deleteContainer), new PathStatsQueue(deleteContainer));
+        requestsMap.put(Request.op2String(delete), new PathStatsQueue(delete));
+        requestsMap.put(Request.op2String(exists), new PathStatsQueue(exists));
+        requestsMap.put(Request.op2String(setData), new PathStatsQueue(setData));
+        requestsMap.put(Request.op2String(getData), new PathStatsQueue(getData));
+        requestsMap.put(Request.op2String(getACL), new PathStatsQueue(getACL));
+        requestsMap.put(Request.op2String(setACL), new PathStatsQueue(setACL));
+        requestsMap.put(Request.op2String(getChildren), new PathStatsQueue(getChildren));
+        requestsMap.put(Request.op2String(getChildren2), new PathStatsQueue(getChildren2));
+        requestsMap.put(Request.op2String(checkWatches), new PathStatsQueue(checkWatches));
+        requestsMap.put(Request.op2String(removeWatches), new PathStatsQueue(removeWatches));
+        requestsMap.put(Request.op2String(sync), new PathStatsQueue(sync));
+        this.immutableRequestsMap = java.util.Collections.unmodifiableMap(requestsMap);
+    }
+
+    static boolean isWriteOp(int requestType) {
+        switch (requestType) {
+            case ZooDefs.OpCode.sync:
+            case ZooDefs.OpCode.create:
+            case ZooDefs.OpCode.create2:
+            case ZooDefs.OpCode.createContainer:
+            case ZooDefs.OpCode.delete:
+            case ZooDefs.OpCode.deleteContainer:
+            case ZooDefs.OpCode.setData:
+            case ZooDefs.OpCode.reconfig:
+            case ZooDefs.OpCode.setACL:
+            case ZooDefs.OpCode.multi:
+            case ZooDefs.OpCode.check:
+                return true;
+        }
+        return false;
+    }
+
+    static String trimPathDepth(String path, int maxDepth) {
+        int count = 0;
+        String pathSeparator = "/";
+        StringBuilder sb = new StringBuilder();
+        StringTokenizer pathTokenizer = new StringTokenizer(path, pathSeparator);
+        while (pathTokenizer.hasMoreElements() && count++ < maxDepth) {
+            sb.append(pathSeparator);
+            sb.append(pathTokenizer.nextToken());
+        }
+        path = sb.toString();
+        return path;
+    }
+
+    @Override
+    protected void finalize() {
 
 Review comment:
   I think this is not needed and nowadays finalize() is not to be used anymore
   can we drop this method ?

----------------------------------------------------------------
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