maedhroz commented on code in PR #2534:
URL: https://github.com/apache/cassandra/pull/2534#discussion_r1319315170


##########
src/java/org/apache/cassandra/metrics/AccordStateCacheMetrics.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.cassandra.metrics;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import com.codahale.metrics.Histogram;
+import org.apache.cassandra.cache.CacheSize;
+
+import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
+
+public class AccordStateCacheMetrics extends CacheMetrics
+{
+    public final Histogram objectSize;
+
+    /**
+     * Create metrics for given cache.
+     *
+     * @param type  Type of Cache to identify metrics.
+     * @param cache Cache to measure metrics
+     */
+    public AccordStateCacheMetrics(String type, CacheSize cache)
+    {
+        super(type, cache);
+
+        objectSize = Metrics.histogram(factory.createMetricName("ObjectSize"), 
false);
+    }
+
+    public static class Provider
+    {
+        public static final String ACCORD_STATE_CACHE = "accord-state-cache";
+
+        private final Set<CacheSize> globalCacheSizes;
+        private final AccordStateCacheMetrics globalMetrics;
+
+        private final Map<Class<?>, AccordStateCacheMetrics> instanceMetrics;
+        private final Map<Class<?>, Set<CacheSize>> instanceCacheSizes;
+
+        private final String type;
+
+        public Provider()
+        {
+            this(ACCORD_STATE_CACHE);
+        }
+
+        @VisibleForTesting
+        public Provider(String type)
+        {
+            this.type = type;
+            globalCacheSizes = new CopyOnWriteArraySet<>();
+            globalMetrics = new AccordStateCacheMetrics(type, new 
CacheSize.Summing(globalCacheSizes));
+            instanceMetrics = new HashMap<>(2);
+            instanceCacheSizes = new HashMap<>(2);
+        }
+
+        public synchronized AccordStateCacheMetrics forInstance(Class<?> 
klass, CacheSize commandStoreInstanceCacheSize)
+        {
+            Set<CacheSize> cacheSizes = 
instanceCacheSizes.computeIfAbsent(klass, k -> new CopyOnWriteArraySet<>());
+            cacheSizes.add(commandStoreInstanceCacheSize);
+            return instanceMetrics.computeIfAbsent(klass, k -> new 
AccordStateCacheMetrics(String.format("%s-%s", type, k.getSimpleName()), new 
CacheSize.Summing(cacheSizes)));

Review Comment:
   > We do not have to worry about summing up cache access metrics (hits, 
misses, requests) across different command stores because they all are reported 
to the same metrics instances.
   
   Right. Understand that part.
   
   > For CacheSize, I believe we need to do summing on demand because the cache 
size can be individually set on each AccordCommandStore
   
   Again, agreed. I think where we still have things to resolve are:
   
   1.) What's the most straightforward way to expose the summed sizes (see this 
thread https://github.com/apache/cassandra/pull/2534/files#r1317595176)
   
   2.) Whether we really want to worry about exposing the `CacheSize` bits for 
the instance views at all. Again, we're talking about the same physical cache 
for all instances, right? Even if we don't do that right now in this patch, we 
could always add it later if there was a really compelling reason. This is why 
I suggested something like a `CacheAccessMetrics` that could just worry about 
exposing the hist/misses/etc. items for the `Instance` caches, which don't have 
to be summed at all.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to