Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support setting core pool size for async API in system property #2632

Merged
merged 3 commits into from Oct 4, 2023

Conversation

olavloite
Copy link
Collaborator

Add support for setting the core pool size for the thread pool that is used for the Async API using a system property. This allows users to change this property without having to change code, and to set the property if they are using a framework that builds on top of the client library, but that does not have a configuration option for setting a custom executor provider.

Fixes #2631

Add support for setting the core pool size for the thread pool that is
used for the Async API using a system property. This allows users to
change this property without having to change code, and to set the
property if they are using a framework that builds on top of the client
library, but that does not have a configuration option for setting a
custom executor provider.

Fixes #2631
@olavloite olavloite requested a review from a team as a code owner September 18, 2023 09:05
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/java-spanner API. labels Sep 18, 2023
@gcf-owl-bot gcf-owl-bot bot requested a review from a team as a code owner September 18, 2023 09:08
@@ -913,6 +914,49 @@ public void testCustomAsyncExecutorProvider() {
assertSame(service, options.getAsyncExecutorProvider().getExecutor());
}

@Test
public void testAsyncExecutorProviderCoreThreadCount() throws Exception {
assertEquals(8, SpannerOptions.getDefaultAsyncExecutorProviderCoreThreadCount());
Copy link
Collaborator

@arpan14 arpan14 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we add a check to ensure that the system property was originally unset? Or maybe explicitly set the property to null?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that there is a handling of this scenario within the finally block of runWithSystemProperty method, but thought if explicitly setting null would be better to ensure that the default behaviour is due to null property and not because somehow the property was already set to 8.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test for both null and an empty string.

@olavloite olavloite added the automerge Merge the pull request once unit tests and other checks pass. label Oct 4, 2023
@gcf-merge-on-green gcf-merge-on-green bot merged commit e51c55d into main Oct 4, 2023
24 checks passed
@gcf-merge-on-green gcf-merge-on-green bot deleted the async-executor-threads-property branch October 4, 2023 12:48
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Oct 4, 2023
surbhigarg92 pushed a commit to surbhigarg92/java-spanner that referenced this pull request Oct 5, 2023
…googleapis#2632)

Add support for setting the core pool size for the thread pool that is used for the Async API using a system property. This allows users to change this property without having to change code, and to set the property if they are using a framework that builds on top of the client library, but that does not have a configuration option for setting a custom executor provider.

Fixes googleapis#2631

@VisibleForTesting
static int getDefaultAsyncExecutorProviderCoreThreadCount() {
String propertyName = "SPANNER_ASYNC_NUM_CORE_THREADS";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic string!

should we maintain list of constants/enums property names?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set number of threads for async executor provider as a system property
3 participants