Skip to content

Commit 4bec6a1

Browse files
committed
[grid] Reduce redundant logs of find slots and retry queue requests by the Distributor
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent ef0f66c commit 4bec6a1

File tree

3 files changed

+363
-6
lines changed

3 files changed

+363
-6
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,14 @@ protected Set<NodeStatus> getAvailableNodes() {
512512
try {
513513
return model.getSnapshot().stream()
514514
.filter(
515-
node ->
516-
!DOWN.equals(node.getAvailability()) && !DRAINING.equals(node.getAvailability()))
515+
node -> {
516+
// Only consider UP nodes (not DOWN, DRAINING, etc.)
517+
if (!UP.equals(node.getAvailability())) {
518+
return false;
519+
}
520+
// Consider node has at least one free slot
521+
return node.getSlots().stream().anyMatch(slot -> slot.getSession() == null);
522+
})
517523
.collect(toImmutableSet());
518524
} finally {
519525
readLock.unlock();
@@ -704,8 +710,7 @@ private SlotId reserveSlot(RequestId requestId, Capabilities caps) {
704710
}
705711

706712
private boolean isNotSupported(Capabilities caps) {
707-
return getAvailableNodes().stream()
708-
.noneMatch(node -> node.hasCapability(caps, slotMatcher) && node.getAvailability() == UP);
713+
return getAvailableNodes().stream().noneMatch(node -> node.hasCapability(caps, slotMatcher));
709714
}
710715

711716
private boolean reserve(SlotId id) {
@@ -795,7 +800,7 @@ public void run() {
795800
// up starving a session request.
796801
Map<Capabilities, Long> stereotypes =
797802
getAvailableNodes().stream()
798-
.filter(node -> node.hasCapacity() && node.getAvailability() == UP)
803+
.filter(NodeStatus::hasCapacity)
799804
.flatMap(node -> node.getSlots().stream().map(Slot::getStereotype))
800805
.collect(
801806
Collectors.groupingBy(ImmutableCapabilities::copyOf, Collectors.counting()));

java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.openqa.selenium.grid.data.TraceSessionRequest;
5656
import org.openqa.selenium.grid.distributor.config.DistributorOptions;
5757
import org.openqa.selenium.grid.jmx.JMXHelper;
58+
import org.openqa.selenium.grid.jmx.MBean;
5859
import org.openqa.selenium.grid.jmx.ManagedAttribute;
5960
import org.openqa.selenium.grid.jmx.ManagedService;
6061
import org.openqa.selenium.grid.log.LoggingOptions;
@@ -110,6 +111,7 @@ public class LocalNewSessionQueue extends NewSessionQueue implements Closeable {
110111
thread.setName(NAME);
111112
return thread;
112113
});
114+
private final MBean jmxBean;
113115

114116
public LocalNewSessionQueue(
115117
Tracer tracer,
@@ -139,7 +141,8 @@ public LocalNewSessionQueue(
139141
requestTimeoutCheck.toMillis(),
140142
MILLISECONDS);
141143

142-
new JMXHelper().register(this);
144+
// Manage JMX and unregister on close()
145+
this.jmxBean = new JMXHelper().register(this);
143146
}
144147

145148
public static NewSessionQueue create(Config config) {
@@ -502,6 +505,10 @@ public boolean isReady() {
502505
@Override
503506
public void close() {
504507
shutdownGracefully(NAME, service);
508+
509+
if (jmxBean != null) {
510+
new JMXHelper().unregister(jmxBean.getObjectName());
511+
}
505512
}
506513

507514
private void failDueToTimeout(RequestId reqId) {

0 commit comments

Comments
 (0)