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

AwsDefaultClientBuilder.mergeChildDefaults() instantiates DefaultCredentialsProvider which is expensive #749

Closed
stuartleylandcole opened this issue Oct 4, 2018 · 3 comments
Labels
2.0 New feature-request A feature should be added or improved.

Comments

@stuartleylandcole
Copy link

Expected Behavior

Specifying a AwsCredentialsProvider on a service client should avoid the need to create an instance of DefaultCredentialsProvider, which in turn creates 5 implementations of AwsCredentialsProvider as part of the chain.

Current Behavior

If I've understood the code correctly, I think the reasoning for the current behaviour is to create a config with the defaults then merge this with any user-supplied configuration, resulting in a properly configured object. The code path for this is:

  • (In user code) DynamoDbClient.builder().build()
    • software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration()
      • software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.mergeChildDefaults(SdkClientConfiguration)
        • software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider.create()

Possible Solution

I wonder if it's possible to add the user configuration first, and only add defaults for any properties not provided by the user? I guess this would be a change in software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration()

Steps to Reproduce (for bugs)

The following code will take you down the code path I highlighted above

DynamoDbClient.builder().build()

Context

I am using the SDK in a Lambda which CRUDs data in a DynamoDB table. The Lambdas provide the API for my client so need to be responsive; creating the DynamoDbClient is by far the slowest part of starting my Lambda (provisioning aside, which I can't control) and this is one of the slowest parts as best I can tell from stepping through the code. Populating the Partitions object from endpoints.json is also slow but that is captured in #748

Your Environment

  • AWS Java SDK version used: 2.0.0-preview-12
  • JDK version used: 8 (provided by AWS Lambda)
  • Operating System and version: N/A
@spfink
Copy link
Contributor

spfink commented Oct 4, 2018

This is another area that we are looking to improve in regards to cold start latency before we GA.

As an aside, are you using the UrlConnectionClient? It should provide a reduction in cold start latency over the Apache Http client.

@stuartleylandcole
Copy link
Author

@spfink that's great to know, I'm very excited by SDK version 2, it looks like it will be a fantastic update - thanks for your work 👍

Yes, I'm using UrlConnectionHttpClient and, compared to v1 using Apache HTTP Client, it seems to have taken about 0.5-1s off the start up time, I'm now around 1.0-1.2s vs 1.7-2.0s.

millems added a commit that referenced this issue Feb 7, 2019
The default credentials provider chain and region provider chains will no longer be loaded until they are first used. Further, the profile credentials provider will never raise an exception when it is created. The exception won't be raised until it is first used.

Fixes #1030, #1014, #749
millems added a commit that referenced this issue Feb 8, 2019
The default credentials provider chain and region provider chains will no longer be loaded until they are first used. Further, the profile credentials provider will never raise an exception when it is created. The exception won't be raised until it is first used.

Fixes #1030, #1014, #749
@justnance justnance added feature-request A feature should be added or improved. and removed Feature Request labels Apr 19, 2019
@millems
Copy link
Contributor

millems commented Jul 8, 2019

The region and credentials providers are now lazily initialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 New feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

5 participants