You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/08/04 12:24:21 UTC

[GitHub] [ozone] adoroszlai commented on a diff in pull request #3626: HDDS-7053. Add client-side writeChunk metrics

adoroszlai commented on code in PR #3626:
URL: https://github.com/apache/ozone/pull/3626#discussion_r937612949


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/ContainerClientMetrics.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.hadoop.hdds.scm;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
+import org.apache.hadoop.metrics2.annotation.Metric;
+import org.apache.hadoop.metrics2.annotation.Metrics;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.lib.Interns;
+import org.apache.hadoop.metrics2.lib.MetricsRegistry;
+import org.apache.hadoop.metrics2.lib.MutableCounterLong;
+import org.apache.hadoop.ozone.OzoneConsts;
+
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Container client metrics that describe how data writes are distributed to
+ * pipelines.
+ */
+@Metrics(about = "Client Metrics", context = OzoneConsts.OZONE)
+public final class ContainerClientMetrics {
+  private static ContainerClientMetrics instance;
+  private static int referenceCount = 0;
+
+  private static final String SOURCE_NAME =
+      ContainerClientMetrics.class.getSimpleName();
+
+  @Metric
+  private MutableCounterLong totalWriteChunkCalls;
+  @Metric
+  private MutableCounterLong totalWriteChunkBytes;
+  private final Map<PipelineID, MutableCounterLong> writeChunkCallsByPipeline;
+  private final Map<PipelineID, MutableCounterLong> writeChunkBytesByPipeline;
+  private final Map<UUID, MutableCounterLong> writeChunksCallsByLeaders;
+  private final MetricsRegistry registry;
+
+  public static synchronized ContainerClientMetrics acquire() {
+    if (instance == null) {
+      instance = newInstance();
+    }
+    referenceCount++;
+    return instance;
+  }
+
+  @VisibleForTesting
+  public static ContainerClientMetrics newInstance() {
+    return DefaultMetricsSystem.instance().register(SOURCE_NAME,
+        "Ozone Client Metrics", new ContainerClientMetrics());
+  }
+
+  public static synchronized void release() {
+    referenceCount--;

Review Comment:
   I think it should warn and return if `instance` is already `null`, before decrementing reference count.  Otherwise `release()` without `acquire()` (programming error) could mess up the count.



##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/ContainerClientMetrics.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.hadoop.hdds.scm;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
+import org.apache.hadoop.metrics2.annotation.Metric;
+import org.apache.hadoop.metrics2.annotation.Metrics;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.lib.Interns;
+import org.apache.hadoop.metrics2.lib.MetricsRegistry;
+import org.apache.hadoop.metrics2.lib.MutableCounterLong;
+import org.apache.hadoop.ozone.OzoneConsts;
+
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Container client metrics that describe how data writes are distributed to
+ * pipelines.
+ */
+@Metrics(about = "Client Metrics", context = OzoneConsts.OZONE)
+public final class ContainerClientMetrics {
+  private static ContainerClientMetrics instance;
+  private static int referenceCount = 0;
+
+  private static final String SOURCE_NAME =
+      ContainerClientMetrics.class.getSimpleName();
+
+  @Metric
+  private MutableCounterLong totalWriteChunkCalls;
+  @Metric
+  private MutableCounterLong totalWriteChunkBytes;
+  private final Map<PipelineID, MutableCounterLong> writeChunkCallsByPipeline;
+  private final Map<PipelineID, MutableCounterLong> writeChunkBytesByPipeline;
+  private final Map<UUID, MutableCounterLong> writeChunksCallsByLeaders;
+  private final MetricsRegistry registry;
+
+  public static synchronized ContainerClientMetrics acquire() {
+    if (instance == null) {
+      instance = newInstance();
+    }
+    referenceCount++;
+    return instance;
+  }
+
+  @VisibleForTesting
+  public static ContainerClientMetrics newInstance() {
+    return DefaultMetricsSystem.instance().register(SOURCE_NAME,
+        "Ozone Client Metrics", new ContainerClientMetrics());

Review Comment:
   It seems metrics system expects name to be unique, even after unregister/register cycle.  We can achieve that by adding an instance counter and generating name as `SOURCE_NAME + counter` when creating new instance, and then using it in `release()`, too.



##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/BlockOutputStreamEntryPool.java:
##########
@@ -140,6 +144,7 @@ ExcludeList createExcludeList() {
     currentStreamIndex = 0;
     openID = -1;
     excludeList = new ExcludeList();
+    clientMetrics = ContainerClientMetrics.newInstance();

Review Comment:
   Unfortunately the comment "constructor for testing purpose only" is no longer valid, this is used for EC (via [implicit `super()` call in `ECKeyOutputStream`](https://github.com/apache/ozone/blob/348fcb615783daae33e36d8ca7402ca4182e838a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/ECKeyOutputStream.java#L94-L95)).  Is it possible to avoid creating the metrics instance here?  If not, it will need to go via `acquire()`, and then needs to be released somewhere.
   
   Acceptance test failure with EC bucket is failing due to this:
   https://github.com/apache/ozone/runs/7658098860?check_suite_focus=true#step:5:322



-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org