Skip to content

Allow StsCredentialsProvider builder to take a ScheduledExecutorService #3260

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

Closed

Conversation

cloudshiftchris
Copy link

@cloudshiftchris cloudshiftchris commented Jun 21, 2022

Allow StsCredentialsProvider builder to take a ScheduledExecutorService for more efficient background processing.

Motivation and Context

See #3259.
Reduces the number of threads required for async refresh of credentials. In multi-tenant setups there can be large numbers of StsCredentialsProvider instances - maintaining a background thread for each one is unnecessary and expensive; this change allows for a shared ScheduledExecutorService to be used to reduce resource consumption.

Modifications

Provide additional constructors on software.amazon.awssdk.utils.cache.NonBlocking to take a ScheduledExecutorService (instead of creating one).
Modify software.amazon.awssdk.utils.cache.NonBlocking.close() to only cleanup executor service if owned (created) by this instance.
Modify software.amazon.awssdk.services.sts.auth.StsCredentialsProvider to allow a ScheduledExecutorService to be provided via the builder. When provided, the appropriate NonBlocking constructor is used.

Testing

Added additional test cases mirroring existing NonBlocking test cases to confirm no change in behaviour.

Screenshots (if appropriate)

n/a

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

…ecutorService for more efficient background processing, in the case where there are large numbers of credentials providers (e.g. a multi-tenant setup).
@cloudshiftchris cloudshiftchris requested a review from a team as a code owner June 21, 2022 17:15
@millems
Copy link
Contributor

millems commented Jun 29, 2022

Nice contribution! What if the SDK by default shared threads between NonBlocking instances so that you don't have to configure it yourself? Is there a specific reason you want a custom thread pool?

@cloudshiftchris
Copy link
Author

cloudshiftchris commented Jun 29, 2022 via email

@millems
Copy link
Contributor

millems commented Jun 29, 2022

Let me take a swing at doing it within the SDK. The main challenge is scheduled executors only working with core threads, and core threads not being reused (even if idle), but we can probably work around that with a couple of executors or something more clever.

It would be nice if everyone got this improvement, not just people 'in the know'.

@cloudshiftchris
Copy link
Author

cloudshiftchris commented Jun 29, 2022 via email

@cloudshiftchris
Copy link
Author

cloudshiftchris commented Jun 29, 2022 via email

@millems
Copy link
Contributor

millems commented Jun 29, 2022

Oh yeah, jitter is a good idea, didn't think about that.

@millems
Copy link
Contributor

millems commented Jun 29, 2022

My swing: #3275

If it looks good to you, did you want to try it out to make sure you see the resource consumption reduction you expect?

@cloudshiftchris
Copy link
Author

@millems great work; added a few comments. Travelling atm (for the remainder of the week), won't be able to directly test, though the resource consumption improvements are evident in the removal of the per-cred-provider executor.

Thanks for tackling this.

@millems
Copy link
Contributor

millems commented Jun 30, 2022

I don't see your feedback on the PR. Did you miss hitting publish, or am I blind?

@cloudshiftchris
Copy link
Author

cloudshiftchris commented Jun 30, 2022 via email

@cloudshiftchris
Copy link
Author

cloudshiftchris commented Jun 30, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants