You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2022/11/08 13:11:12 UTC

[GitHub] [sling-org-apache-sling-jcr-resource] rombert commented on a diff in pull request #38: SLING-11654 implement AccessMetrics

rombert commented on code in PR #38:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/38#discussion_r1016614651


##########
src/main/java/org/apache/sling/jcr/resource/internal/helper/AccessLogger.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.sling.jcr.resource.internal.helper;
+
+import java.io.Closeable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *  Helper class to report on repository access.
+ *  
+ *  The focus is to have a less overhead as possible if it is not used; in case it is enabled and access
+ *  is logged, the performance overhead does not matter.
+ *  
+ *  In the current implementation it has 2 features:
+ *  * Write a stacktrace on every recorded operation; this comes with a massive overhead and it is definitely
+ *    not recommended to turn this on on production, since it can easily create 100s of megabytes of log and will slow
+ *    down processing massively. To use this turn on TRACE logging on 'org.apache.sling.jcr.resource.AccessLogger.operation'
+ *  * When a resource resolver is closed, dump a single log statement about the number of recorded operations. The overhead is
+ *    very small and it can be turned on for a longer period of time also in production. To use it enable DEBUG logging on
+ *    'org.apache.sling.jcr.resource.AccessLogger.statistics'.
+ *  
+ *
+ */
+public class AccessLogger implements Closeable {
+    
+    
+    Map<String,AtomicLong> metrics = new HashMap<>();

Review Comment:
   @joerghoh  - this `HashMap` is not suitable for concurrent access, even though keys and values are thread-safe. It is possible to enter an endless loop while working with the map under certain circumstances.



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

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org