Comments (12)
Hello Luis, can you initialize the block bellow outside the handleRequest
, and retest?
public static SSMProvider ssmProvider = ParamManager.getSsmProvider();
@Override
public String handleRequest(Object o, Context context) {
LambdaLogger logger = context.getLogger();
Instant start = Instant.now();
String ssmParameter = ssmProvider.withDecryption().get("test-parameter");
logger.log("ssm parameter: " + ssmParameter);
Instant finish = Instant.now();
logger.log("Total duration SSM: " + Duration.between(start, finish).toMillis());
return ssmParameter;
}
from powertools-lambda-java.
Hello @dgomesbr , thanks for your quick reply.
Declaring the variable as static improved the performance, now it takes 4-5 seconds to fetch the SSM parameter (cold start, further requests takes less than a second).
thanks!
from powertools-lambda-java.
@msailes Let's review the docs to push this practices on the docs
I will have a look at this later tonight
from powertools-lambda-java.
Isn’t 4-5 seconds too high?
Any other optimisation that can be shared with customers?
Indeed, I will have a look at this, validate and suggest if this can be optimised in some way.
from powertools-lambda-java.
I think declaring clients static outside the handler reducing the init time applies to almost every SDK client. I have experienced this with SSM, Dynamo, SQS, and SNS clients.IMO this behavior needs to be more publicized and even better if it is enforced at the SDK level. At work, we kind of followed a factory approach where all expensive clients are initialized above the handler function and the approach has yielded good results. One important thing to remember is to make sure that the total initialization time doesn't exceed more than 10 seconds.
from powertools-lambda-java.
@msailes Let's review the docs to push this practices on the docs
from powertools-lambda-java.
from powertools-lambda-java.
It turns out during initial fetch, most of the time taken is by SSMClient itself. Next remote invocations of SSMClient is quite fast.
Total time fetching via SSM Client
is the time spent internally by SSMClient in AWS SDK.
Total duration powertools SSM
is time which is taken by powertools client.
1st call to SDK client is surprisingly slow.
So nothing much is happening inside powertools, most of it is from SDK client itself.
from powertools-lambda-java.
Diving a bit more into the observation above and following this discussion which is on the same lines.
There are few things which can be done:
- Just increasing functions memory from 512 MB to 2048 MB, Significantly reduces the initial fetch time. From ~3 seconds to less than 1 seconds. @luismospinam This can be a thing to try out.
- There are few other other options that you can take to further optimise the initial fetch time.
Library provides you a way to pass the customer SSM/Secret manager client. You can for now configure the customer client like this:
private static final SSMProvider ssmProvider = ParamManager.getSsmProvider(SsmClient.builder()
.httpClientBuilder(UrlConnectionHttpClient.builder())
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build());
I will create a release tomorrow to make this the default configuration and also update docs.
from powertools-lambda-java.
@msailes Let's review the docs to push this practices on the docs
I will have a look at this later tonight
Just looked at the docs, and the example kind of already guides to initialize ssm/secret provider outside the handler method. Can we make this more explicit somehow ? 🤔
from powertools-lambda-java.
@luismospinam Just wondering if you got chance to try out some of the options mentioned above ?
from powertools-lambda-java.
Default SDK clients used by library for parameters modules have been further optimized in release v1.0.1. Closing this issue for now. Thanks @luismospinam for raising the issue. :)
from powertools-lambda-java.
Related Issues (20)
- Trace Annotations not getting added if Annotation Key has a space in it HOT 11
- Putting metrics fails when POWERTOOLS_METRICS_NAMESPACE is not set HOT 3
- Logging: Trace ID not logged with Java 17 runtime HOT 1
- Feature enhancement: Create a Subsegments for operations handled by Powertools HOT 5
- Logging: print `message` as JSON, instead of wrapping into a string HOT 14
- Exceptions not showing in Traces HOT 1
- RFC: Introduce Version 2
- RFC: Remove support for Java 8 in V2 HOT 7
- Feature enhancement (Logger): automatically intercept Runtime exceptions, and log information HOT 7
- Log level not restored at the end of execution HOT 2
- Support batch secrets retrieval in Parameters module HOT 6
- Maintenance: update jackson and aws-xray-recorder dependencies together HOT 4
- RFC: handle batch messages in parallel in batch module HOT 12
- v2: Example logging configuration needs to be updated HOT 3
- v2 - Params builders do not supply default TransformationManager HOT 1
- bug - v2 - end-to-end tests broken
- AbstractCustomResourceHandler - Unable to send response HOT 2
- LambdaEcsLayout seems to incorrectly serialize the service field HOT 7
- Add support for CRaC
- RFC: support for multi-endpoint HTTP handler Lambda functions HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powertools-lambda-java.