Giter Club home page Giter Club logo

Comments (5)

alexcasalboni avatar alexcasalboni commented on June 2, 2024

Hi @zombaki 👋 thanks for asking :)

It really depends on what your function is doing. Could you share more details about the function to power-tune?

For example, if your function needs to delete a record from a database, I'd recommend setting up a pre-processor to create the record in the database. Because all power configurations will run in parallel (even with parallelInvocation: false), you might need to randomize the ID / primary key, so that a few invocations can work in parallel.

To achieve that, you need to create a Lambda function that will act as pre-processor and then provide it as preProcessorARN when you run the state machine. This pre-processor will receive the original invocation payload and will be able to return an altered payload for the actual power-tuning invocation.

It looks like this:

function Executor:
  iterate from 0 to num:
    [alteredPayload = execute Pre-processor (payload)]
    results = execute Main Function (alteredPayload)

Let me know if you need more help/info, or if your use case is different.

from aws-lambda-power-tuning.

zombaki avatar zombaki commented on June 2, 2024

my limitation is that my lambda can execute once for a particular payload, so wanted to know if i can pass multiple payloads for execution, so that a payload is used only once!

from aws-lambda-power-tuning.

alexcasalboni avatar alexcasalboni commented on June 2, 2024

You can pass multiple payloads using weighted payloads.

For example, with num: 10 you could pass 10 different payloads (see example below).

This way, each payload would be used only once *for each power configuration*.

{
    "parallelInvocation": false,
    "num": 10,
    "payload": [
        { "payload": { "key": "A" }, "weight": 1 },
        { "payload": { "key": "B" }, "weight": 1 },
        { "payload": { "key": "C" }, "weight": 1 },
        { "payload": { "key": "D" }, "weight": 1 },
        { "payload": { "key": "E" }, "weight": 1 },
        { "payload": { "key": "F" }, "weight": 1 },
        { "payload": { "key": "G" }, "weight": 1 },
        { "payload": { "key": "H" }, "weight": 1 },
        { "payload": { "key": "I" }, "weight": 1 },
        { "payload": { "key": "J" }, "weight": 1 },
    ]
}

The problem is that each power configuration will use these payloads. For example, if you're power-tuning with powerValues: [128, 256, 512], you will have 3 concurrent Lambda invocations with payload "A", then 3 concurrent invocations with payload "B", and so on.

If your function is interacting with the same database (or service) and you need 100% unique payloads, this won't work.

That is why I recommended using pre-processors above.

from aws-lambda-power-tuning.

alexcasalboni avatar alexcasalboni commented on June 2, 2024

If you implement a pre-processor, you'll be able to do something like this:

{
    "parallelInvocation": true,
    "num": 50,
    "payload": { "key": "A" },
    "preProcessorARN": "ARNofYourPreProcessorFunction"
}

and your pre-processor logic might look like this:

exports.handler =  async function(event, context) {
  const randomString = /* generate random string here */;
  const key = event.key + randomString; // fetch event key from original payload and append random string
  const primaryKey = await db.createNewRecord(key); // create a new db object and fetch new primary key
  return {key: primaryKey}; // return new payload for power-tuning invocation
}

from aws-lambda-power-tuning.

alexcasalboni avatar alexcasalboni commented on June 2, 2024

Closing this for now, please feel free to reopen if the solution above didn't work for you :)

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.