melihsozdinler commented on code in PR #42071:
URL: https://github.com/apache/spark/pull/42071#discussion_r1297743479


##########
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ExternalBlockHandler.java:
##########
@@ -101,19 +113,46 @@ public ExternalShuffleBlockResolver getBlockResolver() {
   public ExternalBlockHandler(
       OneForOneStreamManager streamManager,
       ExternalShuffleBlockResolver blockManager) {
-    this(streamManager, blockManager, new NoOpMergedShuffleFileManager(null, 
null));
+    this(streamManager, blockManager, new NoOpMergedShuffleFileManager(null, 
null), -1);
   }
 
   /** Enables mocking out the StreamManager, BlockManager, and MergeManager. */
   @VisibleForTesting
   public ExternalBlockHandler(
       OneForOneStreamManager streamManager,
       ExternalShuffleBlockResolver blockManager,
-      MergedShuffleFileManager mergeManager) {
+      MergedShuffleFileManager mergeManager,
+      int shuffleDataMetricRefreshPeriodSeconds) {
     this.metrics = new ShuffleMetrics();
     this.streamManager = streamManager;
     this.blockManager = blockManager;
     this.mergeManager = mergeManager;
+
+    if (shuffleDataMetricRefreshPeriodSeconds > 0) {
+      // We need daemon thread for shutdown hooks to be called properly
+      // This is also the reason we are not using ScheduledExecutorService
+      Runnable metricRefresherDaemon = () -> 
regularlyUpdateTotalShuffleDataMetric(
+          shuffleDataMetricRefreshPeriodSeconds);
+      new ThreadFactoryBuilder().setDaemon(true)
+          .setPriority(Thread.MIN_PRIORITY)
+          .setNameFormat("shuffle-data-metrics-refresher")
+          .build()
+          .newThread(metricRefresherDaemon)
+          .start();
+    }
+  }
+
+  private void regularlyUpdateTotalShuffleDataMetric(int refreshPeriod) {
+    while (true) {
+      try {
+        metrics.nodeShuffleMetrics =
+            new AtomicReference<>(blockManager.computeNodeShuffleMetrics());
+        Thread.sleep(1000L * refreshPeriod);
+      } catch (Exception e) {
+        // Catching exceptions so that subsequent executions are not suppressed
+        logger.debug("Exception occurred while calculating shuffle metrics", 
e);

Review Comment:
   Better to use Warn or Error level here, since it is an exception.



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