anmolanmol1234 commented on code in PR #8137:
URL: https://github.com/apache/hadoop/pull/8137#discussion_r2648081702


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AggregateMetricsManager.java:
##########
@@ -0,0 +1,175 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang3.StringUtils;
+import 
org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidConfigurationValueException;
+import org.apache.hadoop.fs.azurebfs.utils.SimpleRateLimiter;
+
+/**
+ * AggregateMetricsManager manages metrics collection and dispatching
+ * for multiple AbfsClients across different accounts.
+ */
+public final class AggregateMetricsManager {
+
+  // Singleton instance of AggregateMetricsManager.
+  private static volatile AggregateMetricsManager instance;
+
+  // Rate limiter to control the rate of dispatching metrics.
+  private static volatile SimpleRateLimiter rateLimiter;
+
+  // Map of account name to MetricsBucket.
+  private final ConcurrentHashMap<String, MetricsBucket> buckets =
+      new ConcurrentHashMap<>();
+
+  // Scheduler for periodic dispatching of metrics.
+  private final ScheduledExecutorService scheduler;
+
+  // Private constructor to enforce singleton pattern.
+  private AggregateMetricsManager(final long dispatchIntervalInMins,
+      final int permitsPerSecond) throws InvalidConfigurationValueException {
+
+    if (dispatchIntervalInMins <= 0) {
+      throw new InvalidConfigurationValueException(
+          "dispatchIntervalInMins must be > 0");
+    }
+
+    if (permitsPerSecond <= 0) {
+      throw new InvalidConfigurationValueException(
+          "permitsPerSecond must be > 0");
+    }
+
+    this.rateLimiter = new SimpleRateLimiter(permitsPerSecond);
+
+    // Initialize scheduler for periodic dispatching of metrics.
+    this.scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
+      Thread t = new Thread(r, "ABFS-Aggregated-Metrics-Dispatcher");
+      t.setDaemon(true);
+      return t;
+    });
+
+    // Schedule periodic dispatching of metrics.
+    this.scheduler.scheduleAtFixedRate(

Review Comment:
   Better to use scheduleWithFixedDelay as scheduleAtFixedRate can overlap 
executions.



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