Skip to content

Commit f604877

Browse files
committed
Improve Node health checks by batch runs
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent b27e15c commit f604877

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

java/src/org/openqa/selenium/grid/distributor/local/LocalNodeRegistry.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Map;
3333
import java.util.Optional;
3434
import java.util.Set;
35-
import java.util.concurrent.CompletableFuture;
3635
import java.util.concurrent.ConcurrentHashMap;
3736
import java.util.concurrent.ScheduledExecutorService;
3837
import java.util.concurrent.TimeUnit;
@@ -404,31 +403,22 @@ private void processBatchesInParallel(List<List<Runnable>> batches, int maxConcu
404403
if (batches.isEmpty()) {
405404
return;
406405
}
407-
List<CompletableFuture<Void>> inFlight = new ArrayList<>();
408-
for (List<Runnable> batch : batches) {
409-
CompletableFuture<Void> fut =
410-
CompletableFuture.runAsync(
411-
() ->
412-
batch.parallelStream()
413-
.forEach(
414-
r -> {
415-
try {
416-
r.run();
417-
} catch (Throwable t) {
418-
LOG.log(
419-
getDebugLogLevel(), "Health check execution failed in batch", t);
420-
}
421-
}),
422-
nodeHealthCheckService);
423-
inFlight.add(fut);
424-
if (inFlight.size() >= maxConcurrentBatches) {
425-
CompletableFuture.allOf(inFlight.toArray(new CompletableFuture[0])).join();
426-
inFlight.clear();
427-
}
428-
}
429-
if (!inFlight.isEmpty()) {
430-
CompletableFuture.allOf(inFlight.toArray(new CompletableFuture[0])).join();
431-
}
406+
407+
// Process batches with controlled parallelism
408+
batches.parallelStream()
409+
.limit(maxConcurrentBatches)
410+
.forEach(
411+
batch ->
412+
batch.parallelStream()
413+
.forEach(
414+
r -> {
415+
try {
416+
r.run();
417+
} catch (Throwable t) {
418+
LOG.log(
419+
getDebugLogLevel(), "Health check execution failed in batch", t);
420+
}
421+
}));
432422
}
433423

434424
private static List<List<Runnable>> partition(List<Runnable> list, int size) {

0 commit comments

Comments
 (0)