m-trieu commented on code in PR #31784:
URL: https://github.com/apache/beam/pull/31784#discussion_r1696158477


##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/work/refresh/ActiveWorkRefresher.java:
##########
@@ -115,32 +132,72 @@ private void invalidateStuckCommits() {
     }
   }
 
+  /** Create {@link Heartbeats} and group them by {@link HeartbeatSender}. */
   private void refreshActiveWork() {
     Instant refreshDeadline = 
clock.get().minus(Duration.millis(activeWorkRefreshPeriodMillis));
+    Map<HeartbeatSender, Heartbeats> heartbeatsBySender =
+        aggregateHeartbeatsBySender(refreshDeadline);
 
+    if (heartbeatsBySender.isEmpty()) {
+      return;
+    }
+
+    if (heartbeatsBySender.size() == 1) {
+      // If there is a single HeartbeatSender, just use the calling thread to 
send heartbeats.
+      Map.Entry<HeartbeatSender, Heartbeats> heartbeat =
+          Iterables.getOnlyElement(heartbeatsBySender.entrySet());
+      sendHeartbeat(heartbeat);
+    } else {
+      // If there are multiple HeartbeatSenders, send out the heartbeats in 
parallel using the
+      // fanOutActiveWorkRefreshExecutor.
+      List<CompletableFuture<Void>> fanOutRefreshActiveWork = new 
ArrayList<>();
+      for (Map.Entry<HeartbeatSender, Heartbeats> heartbeat : 
heartbeatsBySender.entrySet()) {
+        fanOutRefreshActiveWork.add(
+            CompletableFuture.runAsync(
+                () -> sendHeartbeat(heartbeat), 
fanOutActiveWorkRefreshExecutor));
+      }
+
+      // Don't block until we kick off all the refresh active work RPCs.

Review Comment:
   done
   
   is it a large benefit if we reduce the fanout by 1?



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

Reply via email to