Skip to content

Commit 5e0f804

Browse files
committed
Increase parallism when starting sessions
1 parent 3af936c commit 5e0f804

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,32 @@ public class NewSessionRunnable implements Runnable {
556556

557557
@Override
558558
public void run() {
559-
// We deliberately run this outside of a lock: if we're unsuccessful
560-
// starting the session, we just put the request back on the queue.
561-
// This does mean, however, that under high contention, we might end
562-
// up starving a session request.
563-
Set<Capabilities> stereotypes = getAvailableNodes().stream()
564-
.filter(NodeStatus::hasCapacity)
565-
.map(node -> node.getSlots().stream().map(Slot::getStereotype).collect(Collectors.toSet()))
566-
.flatMap(Collection::stream)
567-
.collect(Collectors.toSet());
568-
569-
Optional<SessionRequest> maybeRequest = sessionQueue.getNextAvailable(stereotypes);
570-
maybeRequest.ifPresent(this::handleNewSessionRequest);
559+
int initialSize = sessionQueue.getQueueContents().size();
560+
boolean retry = initialSize != 0;
561+
562+
while (retry) {
563+
// We deliberately run this outside of a lock: if we're unsuccessful
564+
// starting the session, we just put the request back on the queue.
565+
// This does mean, however, that under high contention, we might end
566+
// up starving a session request.
567+
Set<Capabilities> stereotypes =
568+
getAvailableNodes().stream()
569+
.filter(NodeStatus::hasCapacity)
570+
.map(
571+
node ->
572+
node.getSlots().stream()
573+
.map(Slot::getStereotype)
574+
.collect(Collectors.toSet()))
575+
.flatMap(Collection::stream)
576+
.collect(Collectors.toSet());
577+
578+
Optional<SessionRequest> maybeRequest = sessionQueue.getNextAvailable(stereotypes);
579+
maybeRequest.ifPresent(this::handleNewSessionRequest);
580+
581+
int currentSize = sessionQueue.getQueueContents().size();
582+
retry = currentSize != 0 && currentSize != initialSize;
583+
initialSize = currentSize;
584+
}
571585
}
572586

573587
private void handleNewSessionRequest(SessionRequest sessionRequest) {

0 commit comments

Comments
 (0)