You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ad...@apache.org on 2022/10/16 09:56:41 UTC
[ozone] branch master updated: HDDS-7261. Add container location cache metrics. (#3829)
This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new c0de6bcdeb HDDS-7261. Add container location cache metrics. (#3829)
c0de6bcdeb is described below
commit c0de6bcdebee6a4271fc73ea6542902e0eeee28f
Author: Duong Nguyen <du...@gmail.com>
AuthorDate: Sun Oct 16 02:56:35 2022 -0700
HDDS-7261. Add container location cache metrics. (#3829)
---
.../java/org/apache/hadoop/util/CacheMetrics.java | 103 +++++++++++++++++++++
.../org/apache/hadoop/ozone/om/KeyManagerImpl.java | 1 +
.../hadoop/ozone/om/OMPerformanceMetrics.java | 7 ++
.../org/apache/hadoop/ozone/om/OzoneManager.java | 1 +
.../java/org/apache/hadoop/ozone/om/ScmClient.java | 8 ++
5 files changed, 120 insertions(+)
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CacheMetrics.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CacheMetrics.java
new file mode 100644
index 0000000000..8f505f7604
--- /dev/null
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CacheMetrics.java
@@ -0,0 +1,103 @@
+/**
+ * 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.hadoop.util;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheStats;
+import org.apache.hadoop.metrics2.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * Reusable component that emits cache metrics for a particular cache.
+ */
+public final class CacheMetrics implements MetricsSource {
+ enum CacheMetricsInfo implements MetricsInfo {
+ CacheName("Cache Metrics."),
+ Size("Size of the cache."),
+ HitCount("Number of time the lookup methods return a cached value."),
+ HitRate("Ratio of cache requests which were hit."),
+ MissCount("Number of times the requested value is not in the cache."),
+ MissRate("Ratio of cache requests which were missed."),
+ LoadSuccessCount("Number of times the cache successfully " +
+ "load new values"),
+ LoadExceptionCount("Number of times the cache encounters exception " +
+ "loading new values."),
+ EvictionCount("Number of values which were evicted.");
+
+ private final String desc;
+
+ CacheMetricsInfo(String desc) {
+ this.desc = desc;
+ }
+
+ @Override
+ public String description() {
+ return desc;
+ }
+ }
+
+ public static final String SOURCE_NAME =
+ CacheMetrics.class.getSimpleName();
+
+ public static final String NAME = CacheMetrics.class.getSimpleName();
+
+ private final Cache<?, ?> cache;
+ private final String name;
+
+ private CacheMetrics(Cache<?, ?> cache, String name) {
+ this.cache = cache;
+ this.name = name;
+ }
+
+ public static CacheMetrics create(Cache<?, ?> cache, String name) {
+ MetricsSystem ms = DefaultMetricsSystem.instance();
+ return ms.register(NAME, "Cache Metrics",
+ new CacheMetrics(cache, name));
+ }
+
+ @Override
+ public void getMetrics(MetricsCollector collector, boolean all) {
+ MetricsRecordBuilder recordBuilder = collector.addRecord(SOURCE_NAME)
+ .setContext("Cache metrics")
+ .tag(CacheMetricsInfo.CacheName, name);
+ CacheStats stats = cache.stats();
+
+ recordBuilder
+ .addGauge(CacheMetricsInfo.Size, cache.size())
+ .addGauge(CacheMetricsInfo.HitCount, stats.hitCount())
+ .addGauge(CacheMetricsInfo.HitRate, stats.hitRate())
+ .addGauge(CacheMetricsInfo.MissCount, stats.missCount())
+ .addGauge(CacheMetricsInfo.MissRate, stats.missRate())
+ .addGauge(CacheMetricsInfo.LoadExceptionCount,
+ stats.loadExceptionCount())
+ .addGauge(CacheMetricsInfo.LoadSuccessCount,
+ stats.loadSuccessCount())
+ .addGauge(CacheMetricsInfo.EvictionCount,
+ stats.evictionCount());
+
+ }
+
+ public void unregister() {
+ MetricsSystem ms = DefaultMetricsSystem.instance();
+ ms.unregisterSource(NAME);
+ }
+}
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
index 81ffe46448..12be1cdad8 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
@@ -1971,6 +1971,7 @@ public class KeyManagerImpl implements KeyManager {
.map(BlockLocationInfo::getContainerID)
.collect(Collectors.toSet());
+ metrics.setForceContainerCacheRefresh(forceRefresh);
Map<Long, Pipeline> containerLocations =
scmClient.getContainerLocations(containerIds, forceRefresh);
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMPerformanceMetrics.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMPerformanceMetrics.java
index 870d4c1d5c..ffeb827c59 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMPerformanceMetrics.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMPerformanceMetrics.java
@@ -80,6 +80,9 @@ public class OMPerformanceMetrics {
@Metric(about = "s3VolumeInfo latency nanoseconds")
private MutableRate s3VolumeContextLatencyNs;
+ @Metric(about = "Client requests forcing container info cache refresh")
+ private MutableRate forceContainerCacheRefresh;
+
public void addLookupLatency(long latencyInNs) {
lookupLatencyNs.add(latencyInNs);
@@ -133,4 +136,8 @@ public class OMPerformanceMetrics {
public MutableRate getGetKeyInfoResolveBucketLatencyNs() {
return getKeyInfoResolveBucketLatencyNs;
}
+
+ public void setForceContainerCacheRefresh(boolean value) {
+ forceContainerCacheRefresh.add(value ? 1L : 0L);
+ }
}
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
index 6742aabddf..70f8359fe8 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
@@ -2081,6 +2081,7 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
}
OMPerformanceMetrics.unregister();
RatisDropwizardExports.clear(ratisMetricsMap);
+ scmClient.close();
} catch (Exception e) {
LOG.error("OzoneManager stop failed.", e);
}
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ScmClient.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ScmClient.java
index dbc4ca9f4c..b5e5215eb2 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ScmClient.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ScmClient.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol;
import org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol;
import org.apache.hadoop.hdds.scm.update.client.SCMUpdateServiceGrpcClient;
+import org.apache.hadoop.util.CacheMetrics;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -47,6 +48,7 @@ public class ScmClient {
private final ScmBlockLocationProtocol blockClient;
private final StorageContainerLocationProtocol containerClient;
private final LoadingCache<Long, Pipeline> containerLocationCache;
+ private final CacheMetrics containerCacheMetrics;
private SCMUpdateServiceGrpcClient updateServiceGrpcClient;
ScmClient(ScmBlockLocationProtocol blockClient,
@@ -56,6 +58,8 @@ public class ScmClient {
this.blockClient = blockClient;
this.containerLocationCache =
createContainerLocationCache(configuration, containerClient);
+ this.containerCacheMetrics = CacheMetrics.create(containerLocationCache,
+ "ContainerInfo");
}
static LoadingCache<Long, Pipeline> createContainerLocationCache(
@@ -70,6 +74,7 @@ public class ScmClient {
return CacheBuilder.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(ttl, unit)
+ .recordStats()
.build(new CacheLoader<Long, Pipeline>() {
@NotNull
@Override
@@ -130,5 +135,8 @@ public class ScmClient {
"container location", e.getCause());
}
+ public void close() {
+ containerCacheMetrics.unregister();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org