diff --git a/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java b/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java index f3b9082b78d4d..9eee3b473d7ea 100644 --- a/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java +++ b/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java @@ -45,6 +45,7 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; @@ -137,6 +138,13 @@ public Server asServer(Config initialConfig) { protected void execute(Config config) { Require.nonNull("Config", config); + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + Server server = asServer(config); server.start(); diff --git a/java/src/org/openqa/selenium/grid/commands/Hub.java b/java/src/org/openqa/selenium/grid/commands/Hub.java index 1d94a197c7aa8..f506399bb971d 100644 --- a/java/src/org/openqa/selenium/grid/commands/Hub.java +++ b/java/src/org/openqa/selenium/grid/commands/Hub.java @@ -62,6 +62,7 @@ import java.net.URL; import java.util.Collections; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_OK; @@ -163,7 +164,8 @@ protected Handlers createHandlers(Config config) { secret, distributorOptions.getHealthCheckInterval(), distributorOptions.shouldRejectUnsupportedCaps(), - newSessionRequestOptions.getSessionRequestRetryInterval()); + newSessionRequestOptions.getSessionRequestRetryInterval(), + distributorOptions.getNewSessionThreadPoolSize()); handler.addHandler(distributor); Router router = new Router(tracer, clientFactory, sessions, queue, distributor); @@ -207,6 +209,13 @@ protected Handlers createHandlers(Config config) { protected void execute(Config config) { Require.nonNull("Config", config); + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + Server server = asServer(config).start(); LOG.info(String.format("Started Selenium Hub %s: %s", getServerVersion(), server.getUrl())); diff --git a/java/src/org/openqa/selenium/grid/commands/Standalone.java b/java/src/org/openqa/selenium/grid/commands/Standalone.java index ac894459a854d..c60be37c61e58 100644 --- a/java/src/org/openqa/selenium/grid/commands/Standalone.java +++ b/java/src/org/openqa/selenium/grid/commands/Standalone.java @@ -65,7 +65,9 @@ import java.net.URI; import java.net.URL; import java.util.Collections; +import java.util.Optional; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_OK; @@ -162,7 +164,8 @@ protected Handlers createHandlers(Config config) { registrationSecret, distributorOptions.getHealthCheckInterval(), distributorOptions.shouldRejectUnsupportedCaps(), - newSessionRequestOptions.getSessionRequestRetryInterval()); + newSessionRequestOptions.getSessionRequestRetryInterval(), + distributorOptions.getNewSessionThreadPoolSize()); combinedHandler.addHandler(distributor); Routable router = new Router(tracer, clientFactory, sessions, queue, distributor) @@ -232,6 +235,13 @@ protected Handlers createHandlers(Config config) { protected void execute(Config config) { Require.nonNull("Config", config); + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + Server server = asServer(config).start(); LOG.info(String.format( diff --git a/java/src/org/openqa/selenium/grid/distributor/config/DistributorFlags.java b/java/src/org/openqa/selenium/grid/distributor/config/DistributorFlags.java index 4396c31520c47..a4b7c25586c28 100644 --- a/java/src/org/openqa/selenium/grid/distributor/config/DistributorFlags.java +++ b/java/src/org/openqa/selenium/grid/distributor/config/DistributorFlags.java @@ -33,6 +33,7 @@ import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE; import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_DISTRIBUTOR_IMPLEMENTATION; import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_HEALTHCHECK_INTERVAL; +import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_NEWSESSION_THREADPOOL_SIZE; import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_REJECT_UNSUPPORTED_CAPS; import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_SLOT_MATCHER; import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_SLOT_SELECTOR_IMPLEMENTATION; @@ -92,6 +93,15 @@ public class DistributorFlags implements HasRoles { @ConfigValue(section = DISTRIBUTOR_SECTION, name = "reject-unsupported-caps", example = "true") private boolean rejectUnsupportedCaps = DEFAULT_REJECT_UNSUPPORTED_CAPS; + @Parameter( + names = {"--newsession-threadpool-size"}, + description = "The Distributor uses a fixed-sized thread pool to create new sessions as it consumes new session requests from the queue." + + "This allows configuring the size of the thread pool. The default value is no. of available processors * 3. " + + "Note: If the no. of threads is way greater than the available processors it will not always increase the performance. " + + "A high number of threads causes more context switching which is an expensive operation. ") + @ConfigValue(section = DISTRIBUTOR_SECTION, name = "newsession-threadpool-size", example = "4") + public int newSessionThreadPoolSize = DEFAULT_NEWSESSION_THREADPOOL_SIZE; + @Override public Set getRoles() { return Collections.singleton(DISTRIBUTOR_ROLE); diff --git a/java/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java b/java/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java index 769834012de8e..4a211dc1bab32 100644 --- a/java/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java +++ b/java/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java @@ -38,6 +38,8 @@ public class DistributorOptions { static final String DEFAULT_SLOT_SELECTOR_IMPLEMENTATION = "org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector"; static final boolean DEFAULT_REJECT_UNSUPPORTED_CAPS = false; + static final int DEFAULT_NEWSESSION_THREADPOOL_SIZE = + Runtime.getRuntime().availableProcessors() * 3; private final Config config; public DistributorOptions(Config config) { @@ -117,6 +119,14 @@ public SlotSelector getSlotSelector() { DEFAULT_SLOT_SELECTOR_IMPLEMENTATION); } + public int getNewSessionThreadPoolSize() { + // If the user sets 0 or less, we default to 1 to ensure Grid is running. + return Math.max( + config.getInt(DISTRIBUTOR_SECTION, "newsession-threadpool-size") + .orElse(DEFAULT_NEWSESSION_THREADPOOL_SIZE), + 1); + } + public boolean shouldRejectUnsupportedCaps() { return config.getBool(DISTRIBUTOR_SECTION, "reject-unsupported-caps").orElse(DEFAULT_REJECT_UNSUPPORTED_CAPS); diff --git a/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java b/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java index d512d7038d2cf..7bc47ee98b612 100644 --- a/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java +++ b/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_OK; @@ -116,6 +117,14 @@ protected Handlers createHandlers(Config config) { protected void execute(Config config) { Require.nonNull("Config", config); + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + + Server server = asServer(config).start(); BuildInfo info = new BuildInfo(); diff --git a/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java index 409781892bb53..00f7ed1fe5a2f 100644 --- a/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java +++ b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java @@ -168,15 +168,8 @@ public class LocalDistributor extends Distributor implements Closeable { return thread; }); - private final Executor sessionCreatorExecutor = Executors.newFixedThreadPool( - Runtime.getRuntime().availableProcessors(), - r -> { - Thread thread = new Thread(r); - thread.setName("Local Distributor - Session Creation"); - thread.setDaemon(true); - return thread; - } - ); + private final Executor sessionCreatorExecutor; + private final NewSessionQueue sessionQueue; private final boolean rejectUnsupportedCaps; @@ -191,7 +184,8 @@ public LocalDistributor( Secret registrationSecret, Duration healthcheckInterval, boolean rejectUnsupportedCaps, - Duration sessionRequestRetryInterval) { + Duration sessionRequestRetryInterval, + int newSessionThreadPoolSize) { super(tracer, clientFactory, registrationSecret); this.tracer = Require.nonNull("Tracer", tracer); this.bus = Require.nonNull("Event bus", bus); @@ -217,6 +211,16 @@ public LocalDistributor( } })); + sessionCreatorExecutor = Executors.newFixedThreadPool( + newSessionThreadPoolSize, + r -> { + Thread thread = new Thread(r); + thread.setName("Local Distributor - Session Creation"); + thread.setDaemon(true); + return thread; + } + ); + NewSessionRunnable newSessionRunnable = new NewSessionRunnable(); bus.addListener(NodeDrainComplete.listener(this::remove)); @@ -262,7 +266,8 @@ public static Distributor create(Config config) { secretOptions.getRegistrationSecret(), distributorOptions.getHealthCheckInterval(), distributorOptions.shouldRejectUnsupportedCaps(), - newSessionQueueOptions.getSessionRequestRetryInterval()); + newSessionQueueOptions.getSessionRequestRetryInterval(), + distributorOptions.getNewSessionThreadPoolSize()); } @Override diff --git a/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java b/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java index 044b5944ba1ee..a4b5eb2791e47 100644 --- a/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java +++ b/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java @@ -58,6 +58,7 @@ import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; @@ -227,6 +228,13 @@ public NettyServer start() { protected void execute(Config config) { Require.nonNull("Config", config); + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + Runtime.getRuntime().addShutdownHook(shutdownHook); Server server = asServer(config).start(); diff --git a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java index 29dbb2e90ad75..7c4e73d4042d4 100644 --- a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java +++ b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java @@ -61,6 +61,7 @@ import java.time.Duration; import java.util.Collections; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_OK; @@ -192,6 +193,14 @@ protected Handlers createHandlers(Config config) { protected void execute(Config config) { Require.nonNull("Config", config); + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + + Server server = asServer(config).start(); LOG.info(String.format( diff --git a/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java b/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java index 63353a443871b..4fd4e9d61f3a7 100644 --- a/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java +++ b/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java @@ -35,6 +35,7 @@ import java.util.Collections; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; @@ -103,6 +104,14 @@ protected Handlers createHandlers(Config config) { @Override protected void execute(Config config) { + + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + Server server = asServer(config); server.start(); diff --git a/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java b/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java index df40ef71f9780..59d7df97c5102 100644 --- a/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java +++ b/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java @@ -35,6 +35,7 @@ import java.util.Collections; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; @@ -105,6 +106,13 @@ protected Handlers createHandlers(Config config) { protected void execute(Config config) { Require.nonNull("Config", config); + config.get("server", "max-threads") + .ifPresent(value -> LOG.log(Level.WARNING, + () -> + "Support for max-threads flag is deprecated. " + + "The intent of the flag is to set the thread pool size in the Distributor. " + + "Please use newsession-threadpool-size flag instead.")); + Server server = asServer(config); server.start(); diff --git a/java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java b/java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java index 9e50d2ea8850a..72265b07c2651 100644 --- a/java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java +++ b/java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java @@ -84,6 +84,7 @@ class AddingNodesTest { private static final Capabilities CAPS = new ImmutableCapabilities("cheese", "gouda"); private static final Secret registrationSecret = new Secret("caerphilly"); + private static final int newSessionThreadPoolSize = Runtime.getRuntime().availableProcessors(); private Distributor distributor; private Tracer tracer; @@ -138,7 +139,8 @@ void shouldBeAbleToRegisterALocalNode() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret); @@ -170,7 +172,8 @@ void shouldBeAbleToRegisterACustomNode() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret); @@ -203,7 +206,8 @@ void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxException registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret); @@ -246,7 +250,8 @@ void shouldKeepOnlyOneNodeWhenTwoRegistrationsHaveTheSameUriByListeningForEvents registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret); @@ -282,7 +287,8 @@ void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChange() registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret); diff --git a/java/test/org/openqa/selenium/grid/distributor/DistributorTest.java b/java/test/org/openqa/selenium/grid/distributor/DistributorTest.java index 0c26847ae539a..4f182cb609ef9 100644 --- a/java/test/org/openqa/selenium/grid/distributor/DistributorTest.java +++ b/java/test/org/openqa/selenium/grid/distributor/DistributorTest.java @@ -102,6 +102,7 @@ class DistributorTest { private static final Logger LOG = Logger.getLogger("Distributor Test"); + private static final int newSessionThreadPoolSize = Runtime.getRuntime().availableProcessors(); private final Secret registrationSecret = new Secret("hellim"); private final Wait wait = new FluentWait<>(new Object()).withTimeout(Duration.ofSeconds(5)); private Tracer tracer; @@ -159,7 +160,8 @@ void creatingANewSessionWithoutANodeEndsInFailure() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); Either result = local.newSession(createRequest(caps)); assertThatEither(result).isLeft(); } @@ -221,7 +223,8 @@ void shouldBeAbleToAddANodeAndCreateASession() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -263,7 +266,8 @@ void creatingASessionAddsItToTheSessionMap() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -306,7 +310,8 @@ void shouldBeAbleToRemoveANode() throws MalformedURLException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); Distributor distributor = new RemoteDistributor( tracer, new PassthroughHttpClient.Factory(local), @@ -345,7 +350,8 @@ void testDrainingNodeDoesNotAcceptNewSessions() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); distributor.drain(node.getId()); @@ -383,7 +389,8 @@ void testDrainedNodeShutsDownOnceEmpty() throws InterruptedException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -428,7 +435,8 @@ void drainedNodeDoesNotShutDownIfNotEmpty() throws InterruptedException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -476,7 +484,8 @@ void drainedNodeShutsDownAfterSessionsFinish() throws InterruptedException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -519,7 +528,8 @@ void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); local.add(node); local.add(node); @@ -563,7 +573,8 @@ void theMostLightlyLoadedNodeIsSelectedFirst() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)) + Duration.ofSeconds(5), + newSessionThreadPoolSize) .add(heavy) .add(medium) .add(lightest) @@ -606,7 +617,8 @@ void shouldUseLastSessionCreatedTimeAsTieBreaker() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)) + Duration.ofSeconds(5), + newSessionThreadPoolSize) .add(leastRecent); waitToHaveCapacity(distributor); @@ -690,7 +702,8 @@ void shouldIncludeHostsThatAreUpInHostList() { registrationSecret, Duration.ofSeconds(1), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); distributor.add(alwaysDown); waitForAllNodesToMeetCondition(distributor, 1, DOWN); @@ -740,7 +753,8 @@ void shouldNotScheduleAJobIfAllSlotsAreBeingUsed() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -780,7 +794,8 @@ void shouldReleaseSlotOnceSessionEnds() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -835,7 +850,8 @@ void shouldNotStartASessionIfTheCapabilitiesAreNotSupported() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); Node node = createNode(caps, 1, 0); @@ -875,7 +891,8 @@ void attemptingToStartASessionWhichFailsMarksAsTheSlotAsAvailable() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -920,7 +937,8 @@ void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthCheckPasse registrationSecret, Duration.ofSeconds(1), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); distributor.add(node); waitForAllNodesToMeetCondition(distributor, 1, DOWN); @@ -984,7 +1002,8 @@ void shouldNotRemoveNodeWhoseHealthCheckPassesBeforeThreshold() registrationSecret, Duration.ofSeconds(1), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); distributor.add(node); @@ -1043,7 +1062,8 @@ void shouldPrioritizeHostsWithTheMostSlotsAvailableForASessionType() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); //Create all three Capability types Capabilities edge = new ImmutableCapabilities("browserName", "edge"); @@ -1148,7 +1168,8 @@ void shouldFallbackToSecondAvailableCapabilitiesIfFirstNotAvailable() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); local.add(firstNode); local.add(secondNode); @@ -1191,7 +1212,8 @@ void shouldFallbackToSecondAvailableCapabilitiesIfFirstThrowsOnCreation() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); local.add(brokenNode); local.add(node); waitForAllNodesToHaveCapacity(local, 2); diff --git a/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java b/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java index a67048e00dda2..1c47e5b89ae40 100644 --- a/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java +++ b/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java @@ -83,6 +83,7 @@ class LocalDistributorTest { private final Secret registrationSecret = new Secret("bavarian smoked"); + private static final int newSessionThreadPoolSize = Runtime.getRuntime().availableProcessors(); private Tracer tracer; private EventBus bus; private URI uri; @@ -123,7 +124,8 @@ void testAddNodeToDistributor() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(localNode); DistributorStatus status = distributor.getStatus(); @@ -155,7 +157,8 @@ void testRemoveNodeFromDistributor() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(localNode); //Check the size @@ -188,7 +191,8 @@ void testAddSameNodeTwice() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(localNode); distributor.add(localNode); DistributorStatus status = distributor.getStatus(); @@ -244,7 +248,8 @@ public HttpResponse execute(HttpRequest req) { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); wait.until(obj -> distributor.getStatus().hasCapacity()); @@ -304,7 +309,8 @@ void testDrainNodeFromDistributor() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(localNode); assertThat(localNode.isDraining()).isFalse(); @@ -344,7 +350,8 @@ void testDrainNodeFromNode() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(localNode); localNode.drain(); @@ -370,7 +377,8 @@ void slowStartingNodesShouldNotCauseReservationsToBeSerialized() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); Capabilities caps = new ImmutableCapabilities("browserName", "cheese"); diff --git a/java/test/org/openqa/selenium/grid/graphql/GraphqlHandlerTest.java b/java/test/org/openqa/selenium/grid/graphql/GraphqlHandlerTest.java index d63cf35326c47..5d07d41169adf 100644 --- a/java/test/org/openqa/selenium/grid/graphql/GraphqlHandlerTest.java +++ b/java/test/org/openqa/selenium/grid/graphql/GraphqlHandlerTest.java @@ -83,6 +83,7 @@ class GraphqlHandlerTest { private static final Json JSON = new Json(); + private static final int newSessionThreadPoolSize = Runtime.getRuntime().availableProcessors(); private final Secret registrationSecret = new Secret("stilton"); private final URI publicUri = new URI("http://example.com/grid-o-matic"); private final String version = "4.0.0"; @@ -133,7 +134,8 @@ public void setupGrid() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); } @Test @@ -300,7 +302,8 @@ void shouldBeAbleToGetSessionCount() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); wait.until(obj -> distributor.getStatus().hasCapacity()); @@ -347,7 +350,8 @@ void shouldBeAbleToGetSessionInfo() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); wait.until(obj -> distributor.getStatus().hasCapacity()); @@ -414,7 +418,8 @@ void shouldBeAbleToGetNodeInfoForSession() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); wait.until(obj -> distributor.getStatus().hasCapacity()); @@ -479,7 +484,8 @@ void shouldBeAbleToGetSlotInfoForSession() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); wait.until(obj -> distributor.getStatus().hasCapacity()); @@ -550,7 +556,8 @@ void shouldBeAbleToGetSessionDuration() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); wait.until(obj -> distributor.getStatus().hasCapacity()); diff --git a/java/test/org/openqa/selenium/grid/router/JmxTest.java b/java/test/org/openqa/selenium/grid/router/JmxTest.java index 1c236e2b729d2..ccf6b0f7a6a6d 100644 --- a/java/test/org/openqa/selenium/grid/router/JmxTest.java +++ b/java/test/org/openqa/selenium/grid/router/JmxTest.java @@ -266,7 +266,8 @@ void shouldBeAbleToMonitorHub() throws Exception { secret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + Runtime.getRuntime().availableProcessors()); distributor.add(localNode); diff --git a/java/test/org/openqa/selenium/grid/router/NewSessionCreationTest.java b/java/test/org/openqa/selenium/grid/router/NewSessionCreationTest.java index 4899fc35f1d80..ab69c52da9aca 100644 --- a/java/test/org/openqa/selenium/grid/router/NewSessionCreationTest.java +++ b/java/test/org/openqa/selenium/grid/router/NewSessionCreationTest.java @@ -73,6 +73,7 @@ class NewSessionCreationTest { + private static final int newSessionThreadPoolSize = Runtime.getRuntime().availableProcessors(); private Tracer tracer; private EventBus bus; private HttpClient.Factory clientFactory; @@ -112,7 +113,8 @@ void ensureJsCannotCreateANewSession() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); Routable router = new Router(tracer, clientFactory, sessions, queue, distributor) .with(new EnsureSpecCompliantHeaders(ImmutableList.of(), ImmutableSet.of())); @@ -211,7 +213,8 @@ void shouldNotRetryNewSessionRequestOnUnexpectedError() throws URISyntaxExceptio registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); distributor.add(localNode); @@ -279,7 +282,8 @@ void shouldRejectRequestForUnsupportedCaps() throws URISyntaxException { registrationSecret, Duration.ofMinutes(5), true, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); distributor.add(localNode); diff --git a/java/test/org/openqa/selenium/grid/router/RouterTest.java b/java/test/org/openqa/selenium/grid/router/RouterTest.java index b6f3ee5400b5a..1418003f3071d 100644 --- a/java/test/org/openqa/selenium/grid/router/RouterTest.java +++ b/java/test/org/openqa/selenium/grid/router/RouterTest.java @@ -141,7 +141,8 @@ public void setUp() { registrationSecret, Duration.ofSeconds(1), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + Runtime.getRuntime().availableProcessors()); handler.addHandler(distributor); router = new Router(tracer, clientFactory, sessions, queue, distributor); diff --git a/java/test/org/openqa/selenium/grid/router/SessionCleanUpTest.java b/java/test/org/openqa/selenium/grid/router/SessionCleanUpTest.java index d4655e57db5c0..a5d4b02d5ea03 100644 --- a/java/test/org/openqa/selenium/grid/router/SessionCleanUpTest.java +++ b/java/test/org/openqa/selenium/grid/router/SessionCleanUpTest.java @@ -158,7 +158,8 @@ void shouldRemoveSessionAfterNodeIsShutDownGracefully() { registrationSecret, Duration.ofSeconds(1), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + Runtime.getRuntime().availableProcessors()); handler.addHandler(distributor); Router router = new Router(tracer, clientFactory, sessions, queue, distributor); @@ -278,7 +279,8 @@ void shouldRemoveSessionAfterNodeIsDown() throws URISyntaxException { registrationSecret, Duration.ofSeconds(1), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + Runtime.getRuntime().availableProcessors()); handler.addHandler(distributor); distributor.add(node); diff --git a/java/test/org/openqa/selenium/grid/router/SessionQueueGridTest.java b/java/test/org/openqa/selenium/grid/router/SessionQueueGridTest.java index 15c506b1dd464..6ff95bd17ac7b 100644 --- a/java/test/org/openqa/selenium/grid/router/SessionQueueGridTest.java +++ b/java/test/org/openqa/selenium/grid/router/SessionQueueGridTest.java @@ -139,7 +139,8 @@ public void setup() throws URISyntaxException, MalformedURLException { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + Runtime.getRuntime().availableProcessors()); handler.addHandler(distributor); distributor.add(localNode);