Skip to content

Commit

Permalink
[grid] Improving concurrency session creation by not having a unique …
Browse files Browse the repository at this point in the history
…instance
  • Loading branch information
diemol committed Jul 12, 2021
1 parent dfa7c79 commit 960e168
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class DriverCommandExecutor extends HttpCommandExecutor implements Closeable {

private final DriverService service;
private static final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
private final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
Thread thread = new Thread(r);
thread.setName("Driver Command Executor");
thread.setDaemon(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

package org.openqa.selenium.remote.service;

import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.SECONDS;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
Expand Down Expand Up @@ -49,6 +46,9 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReentrantLock;

import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.SECONDS;

/**
* Manages the life and death of a native executable driver server.
*
Expand All @@ -59,8 +59,9 @@
* used to stop the server.
*/
public class DriverService implements Closeable {

protected static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(20);
private static final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
private final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
Thread thread = new Thread(r);
thread.setName("Driver Service Executor");
thread.setDaemon(true);
Expand All @@ -77,17 +78,15 @@ public class DriverService implements Closeable {
* Controls access to {@link #process}.
*/
private final ReentrantLock lock = new ReentrantLock();

private final String executable;
private final Duration timeout;
private final List<String> args;
private final Map<String, String> environment;
/**
* A reference to the current child process. Will be {@code null} whenever this service is not
* running. Protected by {@link #lock}.
*/
protected CommandLine process = null;

private final String executable;
private final Duration timeout;
private final List<String> args;
private final Map<String, String> environment;
private OutputStream outputStream = System.err;

/**
Expand All @@ -113,25 +112,6 @@ protected DriverService(
this.url = getUrl(port);
}

protected List<String> getArgs() {
return args;
}

protected Map<String, String> getEnvironment() {
return environment;
}

protected URL getUrl(int port) throws IOException {
return new URL(String.format("http://localhost:%d", port));
}

/**
* @return The base URL for the managed driver server.
*/
public URL getUrl() {
return url;
}

/**
*
* @param exeName Name of the executable file to look for in PATH
Expand Down Expand Up @@ -165,6 +145,25 @@ protected static void checkExecutable(File exe) {
Require.stateCondition(exe.canExecute(), "It must be an executable file: %s", exe);
}

protected List<String> getArgs() {
return args;
}

protected Map<String, String> getEnvironment() {
return environment;
}

protected URL getUrl(int port) throws IOException {
return new URL(String.format("http://localhost:%d", port));
}

/**
* @return The base URL for the managed driver server.
*/
public URL getUrl() {
return url;
}

/**
* Checks whether the driver child process is currently running.
*
Expand All @@ -181,12 +180,6 @@ public boolean isRunning() {
}
}

private enum StartOrDie {
SERVER_STARTED,
PROCESS_IS_ACTIVE,
PROCESS_DIED
}

/**
* Starts this service if it is not already running. This method will block until the server has
* been fully started and is ready to handle commands.
Expand Down Expand Up @@ -317,6 +310,12 @@ public void close() {
executorService.shutdownNow();
}

private enum StartOrDie {
SERVER_STARTED,
PROCESS_IS_ACTIVE,
PROCESS_DIED
}

public abstract static class Builder<DS extends DriverService, B extends Builder<?, ?>> {

private int port = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.grid.distributor.local;

import com.google.common.collect.ImmutableSet;

import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
Expand Down Expand Up @@ -58,7 +59,6 @@
import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;
import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;
import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;
import org.openqa.selenium.internal.Debug;
import org.openqa.selenium.internal.Either;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.SessionId;
Expand Down

0 comments on commit 960e168

Please sign in to comment.