Giter Site home page Giter Site logo

Comments (2)

ryancormack avatar ryancormack commented on June 19, 2024 1

Hi Alex,

Thanks for the fast reply.

Your suggestion is much nicer, I think I just started down a rabbit hole and totally looked over the fact there is code invoking the function rather than a Step Function integration invoking it.

I'm happy to go look and pick this proposed solution up 👍🏻

from aws-lambda-power-tuning.

alexcasalboni avatar alexcasalboni commented on June 19, 2024

Hi @ryancormack 👋 thanks for sharing 🙏

I like the idea of a configurable way to sleep X milliseconds between each invocation.

I wouldn't implement it as an actual Wait state in the Step Functions definition. Imho, there are easier ways to achieve the same without making the overall state machine more complex (and expensive) for everyone.

In the past, I've done this by implementing the Thread.sleep(...) logic directly in the function I was power-tuning. The function would sleep only if a special input parameter was given in the payload (something obvious like event.sleepMsForPowertuning.

Alternatively, we could implement an optional sleepBetweenRunsMs input parameter for the state machine, like you suggested. This way, you don't have to implement custom logic in your Lambda functions, across multiple runtimes, etc.

From the point of view of the "usability", as a user you shouldn't care much if it's implemented as a Wait state or as a Thread.sleep(...) in the Executor step. You need to pay for both (there is probably a way to compare how many ms of sleep correspond to a Step Function wait state in terms of $$$). Personally, I'd prefer the second option because it keeps the state machine simple (visually).

Also, each Executor invokes your Function num times, so we actually need to sleep multiple times within the Executor invocation. A Wait state wouldn't be enough.


If we move forward with the second option, the implementation would be fairly simple. We could add a couple of sleeps here and here:


...
if (sleepBetweenRunsMs) {
    await sleep(sleepBetweenRunsMs);
}
...

where sleep looks like this:

function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}

Do you feel like opening a pull-request (PR) for this? Otherwise, I could look into it next week.

from aws-lambda-power-tuning.

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.