Git Product home page Git Product logo

Comments (12)

dgomesbr avatar dgomesbr commented on June 24, 2024 1

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.

luismospinam avatar luismospinam commented on June 24, 2024 1

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.

pankajagrawal16 avatar pankajagrawal16 commented on June 24, 2024 1

@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.

pankajagrawal16 avatar pankajagrawal16 commented on June 24, 2024 1

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.

arjunpunnam avatar arjunpunnam commented on June 24, 2024 1

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.

dgomesbr avatar dgomesbr commented on June 24, 2024

@msailes Let's review the docs to push this practices on the docs

from powertools-lambda-java.

heitorlessa avatar heitorlessa commented on June 24, 2024

from powertools-lambda-java.

pankajagrawal16 avatar pankajagrawal16 commented on June 24, 2024

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.

image

So nothing much is happening inside powertools, most of it is from SDK client itself.

from powertools-lambda-java.

pankajagrawal16 avatar pankajagrawal16 commented on June 24, 2024

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.

pankajagrawal16 avatar pankajagrawal16 commented on June 24, 2024

@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.

pankajagrawal16 avatar pankajagrawal16 commented on June 24, 2024

@luismospinam Just wondering if you got chance to try out some of the options mentioned above ?

from powertools-lambda-java.

pankajagrawal16 avatar pankajagrawal16 commented on June 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.