You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "melihsozdinler (via GitHub)" <gi...@apache.org> on 2023/08/17 20:56:01 UTC

[GitHub] [spark] melihsozdinler commented on a diff in pull request #42071: [SPARK-44209] Expose amount of shuffle data available on the node

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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org