From c206026bed2f011986eeb1aca32181cce6626355 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Thu, 1 Sep 2022 18:25:05 +0530 Subject: [PATCH 1/2] [java] Make new session creation threadpool size configurable --- .../openqa/selenium/grid/commands/Hub.java | 3 +- .../selenium/grid/commands/Standalone.java | 3 +- .../distributor/config/DistributorFlags.java | 10 +++ .../config/DistributorOptions.java | 10 +++ .../distributor/local/LocalDistributor.java | 27 ++++---- .../grid/distributor/AddingNodesTest.java | 16 +++-- .../grid/distributor/DistributorTest.java | 64 +++++++++++++------ .../local/LocalDistributorTest.java | 22 +++++-- .../grid/graphql/GraphqlHandlerTest.java | 19 ++++-- .../openqa/selenium/grid/router/JmxTest.java | 3 +- .../grid/router/NewSessionCreationTest.java | 10 ++- .../selenium/grid/router/RouterTest.java | 3 +- .../grid/router/SessionCleanUpTest.java | 6 +- .../grid/router/SessionQueueGridTest.java | 3 +- 14 files changed, 139 insertions(+), 60 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/commands/Hub.java b/java/src/org/openqa/selenium/grid/commands/Hub.java index 1d94a197c7aa8..f26e4b3879da8 100644 --- a/java/src/org/openqa/selenium/grid/commands/Hub.java +++ b/java/src/org/openqa/selenium/grid/commands/Hub.java @@ -163,7 +163,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); diff --git a/java/src/org/openqa/selenium/grid/commands/Standalone.java b/java/src/org/openqa/selenium/grid/commands/Standalone.java index ac894459a854d..5575b17dff357 100644 --- a/java/src/org/openqa/selenium/grid/commands/Standalone.java +++ b/java/src/org/openqa/selenium/grid/commands/Standalone.java @@ -162,7 +162,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) 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/local/LocalDistributor.java b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java index f86f8d264be1f..1fb8c9364f7b6 100644 --- a/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java +++ b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java @@ -167,15 +167,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; @@ -190,7 +183,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); @@ -216,6 +210,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)); @@ -261,7 +265,8 @@ public static Distributor create(Config config) { secretOptions.getRegistrationSecret(), distributorOptions.getHealthCheckInterval(), distributorOptions.shouldRejectUnsupportedCaps(), - newSessionQueueOptions.getSessionRequestRetryInterval()); + newSessionQueueOptions.getSessionRequestRetryInterval(), + distributorOptions.getNewSessionThreadPoolSize()); } @Override diff --git a/java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java b/java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java index 8c5b10c30fda3..ae35095a7a9a9 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 @@ public 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 @@ public 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 @@ public 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 @@ public void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxEx 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 @@ public void shouldKeepOnlyOneNodeWhenTwoRegistrationsHaveTheSameUriByListeningFo 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 @@ public void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChan 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 7d9ee101d1784..6e5eab05e9f2e 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 @@ public 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 @@ public 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 @@ public void shouldBeAbleToAddANodeAndCreateASession() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -263,7 +266,8 @@ public void creatingASessionAddsItToTheSessionMap() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -306,7 +310,8 @@ public 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 @@ public 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 @@ public 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 @@ public 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 @@ public void drainedNodeShutsDownAfterSessionsFinish() throws InterruptedExceptio registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -519,7 +528,8 @@ public void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); local.add(node); local.add(node); @@ -563,7 +573,8 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)) + Duration.ofSeconds(5), + newSessionThreadPoolSize) .add(heavy) .add(medium) .add(lightest) @@ -606,7 +617,8 @@ public void shouldUseLastSessionCreatedTimeAsTieBreaker() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)) + Duration.ofSeconds(5), + newSessionThreadPoolSize) .add(leastRecent); waitToHaveCapacity(distributor); @@ -690,7 +702,8 @@ public 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 @@ public void shouldNotScheduleAJobIfAllSlotsAreBeingUsed() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -780,7 +794,8 @@ public void shouldReleaseSlotOnceSessionEnds() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -835,7 +850,8 @@ public 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 @@ public void attemptingToStartASessionWhichFailsMarksAsTheSlotAsAvailable() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(node); waitToHaveCapacity(distributor); @@ -920,7 +937,8 @@ public void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthChe 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 @@ public void shouldNotRemoveNodeWhoseHealthCheckPassesBeforeThreshold() registrationSecret, Duration.ofSeconds(1), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); distributor.add(node); @@ -1043,7 +1062,8 @@ public 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 @@ public void shouldFallbackToSecondAvailableCapabilitiesIfFirstNotAvailable() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); local.add(firstNode); local.add(secondNode); @@ -1191,7 +1212,8 @@ public 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 137e1af9c0d9d..07cd920e9f73e 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 @@ public 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 @@ public 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 @@ public void testRemoveNodeFromDistributor() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(localNode); //Check the size @@ -188,7 +191,8 @@ public 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 @@ public 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 @@ public void testDrainNodeFromNode() { registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); distributor.add(localNode); localNode.drain(); @@ -370,7 +377,8 @@ public 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 3dc5c345f4139..56c32de00f3d2 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 @@ public 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 @@ public 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 @@ public 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 @@ public 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 @@ public 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 @@ public 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 7e35a599f114c..4f30927e82a91 100644 --- a/java/test/org/openqa/selenium/grid/router/JmxTest.java +++ b/java/test/org/openqa/selenium/grid/router/JmxTest.java @@ -265,7 +265,8 @@ public 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 3aacbb6f26b64..83bb4837a635a 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 @@ public class NewSessionCreationTest { + private static final int newSessionThreadPoolSize = Runtime.getRuntime().availableProcessors(); private Tracer tracer; private EventBus bus; private HttpClient.Factory clientFactory; @@ -112,7 +113,8 @@ public 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 @@ public void shouldNotRetryNewSessionRequestOnUnexpectedError() throws URISyntaxE registrationSecret, Duration.ofMinutes(5), false, - Duration.ofSeconds(5)); + Duration.ofSeconds(5), + newSessionThreadPoolSize); handler.addHandler(distributor); distributor.add(localNode); @@ -279,7 +282,8 @@ public 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 392a0e79bfd91..0a2f34626203b 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 4a02337247800..f4752327a2149 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 @@ public 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 @@ public 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 f15d50ccd7351..cee7e26272f64 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); From 746e94b6a5097d210c7102cc018ac6c0220484e9 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Fri, 2 Sep 2022 10:25:24 +0530 Subject: [PATCH 2/2] [java] Deprecate max-threads flag --- .../openqa/selenium/grid/commands/EventBusCommand.java | 8 ++++++++ java/src/org/openqa/selenium/grid/commands/Hub.java | 8 ++++++++ .../org/openqa/selenium/grid/commands/Standalone.java | 9 +++++++++ .../grid/distributor/httpd/DistributorServer.java | 9 +++++++++ .../org/openqa/selenium/grid/node/httpd/NodeServer.java | 8 ++++++++ .../openqa/selenium/grid/router/httpd/RouterServer.java | 9 +++++++++ .../selenium/grid/sessionmap/httpd/SessionMapServer.java | 9 +++++++++ .../grid/sessionqueue/httpd/NewSessionQueueServer.java | 8 ++++++++ 8 files changed, 68 insertions(+) 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 f26e4b3879da8..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; @@ -208,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 5575b17dff357..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; @@ -233,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/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/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();