aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

Allow full SDK client initialization for newly created clients based on environment variable

Open aal80 opened this issue 3 years ago • 5 comments
trafficstars

Describe the feature

When creating a new Client object, the client is not fully initialized until the first request is made. It looks like internal components/dependencies are loaded lazily on first client usage. While this might be the desired behavior in some scenarios, this is not always the case. This feature request is for a way to force full client initialization when creating new client objects, preferably using an environment variable.

Use Case

When runing a sequence of SDK requests from a Lambda function configured with default settings, it was observed that the first request always takes significantly longer, up to x100 longer in some cases (~9000ms vs ~80ms). This was tested with DynamoDbClient and SsmClient. The result is a degraded UX for the first function invocation, which is very noticable when developing Lambdas. image image

Proposed Solution

Introduce environment variable that will force full client initialization when present.

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS Java SDK version used

2.17

JDK version used

Corretto 11 in Lambda's Java runtime

Operating System and version

Describe the feature When creating a new Client object, the client is not fully initialized until the first request is made. It looks like internal components/dependencies are loaded lazily on first client usage. While this might be the desired behavior in some scenarios, this is not always the case. This feature request is for a way to force full client initialization when creating new client objects, preferably using an environment variable. Use Case When runing a sequence of SDK requests from a Lambda function configured with default settings, it was observed that the first request always takes significantly longer, up to x100 longer in some cases (~9000ms vs ~80ms). This was tested with DynamoDbClient and SsmClient. The result is a degraded UX for the first function invocation, which is very noticable when developing Lambdas. image image Proposed Solution Introduce environment variable that will force full client initialization when present. Other Information No response Acknowledgements I may be able to implement this feature request This feature might incur a breaking change AWS Java SDK version used Latest on v3 branch JDK version used Corretto 11 in Lambda's Java runtime Operating System and version AL2, Lambda's Java runtime

aal80 avatar Apr 21 '22 14:04 aal80

I'm not a maintainer here but wanted to give my 2 cents: I'd recommend looking into the following (in case you haven't):

  • "Lambda supports the customization of the Java runtime via language-specific environment variables": link
  • "Use the built-in HttpUrlConnection client to reduce instantiation time": link
  • "Introducing Smart Configuration Defaults in the AWS SDK for Java v2": link

orozcoadrian avatar Apr 22 '22 16:04 orozcoadrian

@orozcoadrian Hi Adrian. Thanks for the links! I'm familiar with these techniques, they do help to reduce the cold start times. There's also Tiered Compilation that can be enabled as another technique. What I'm asking for is additional technique that will allow to reduce the cold start invocation time even further, and improve developer experience.

aal80 avatar Apr 25 '22 15:04 aal80

@orozcoadrian thank you for adding the references, that is exactly what I was going to do :)

@aal80 We are curious to understand what exactly do you expect the environment variable would do. For context, one of the reasons why the first call takes longer than the subsequent calls is that the client and the initial connections must be created, and there's really no way to avoid that - you can mitigate it if you initialize the SDK client outside of the Lambda function handler, as mentioned in one of the blog posts.

Have you implemented the suggestions listed in the blog post and is still seeing the 100x difference? Can you send us a sample code we can use to reproduce and also tell us more about how you're doing the benchmarking?

debora-ito avatar Apr 26 '22 00:04 debora-ito

It looks like this issue has not been active for more than five days. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please add a comment to prevent automatic closure, or if the issue is already closed please feel free to reopen it.

github-actions[bot] avatar May 01 '22 03:05 github-actions[bot]

Discussed this with @debora-ito over AWS internal Slack. A work item for the SDK team was opened.

aal80 avatar May 01 '22 21:05 aal80