Comments (5)
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.
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.
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.
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.
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)
- lumigo-cli no longer maintained HOT 2
- Duration being under reported? HOT 3
- adding an option to get all the configurations results HOT 6
- NullReferenceException when testing function HOT 4
- Support for testing stream-based functions HOT 2
- Option to Consume Payload from SQS source? HOT 3
- Actual Payload Shared in Step Functions Console On Function Error HOT 8
- Add KMS permission(s) that may be optionally needed HOT 11
- cost discrepancy on small lambdas HOT 2
- Add logic to identify insufficient resources causing timeout HOT 5
- 💡 Add this project to awesome-italia-opensource HOT 2
- Feature Request: Allow naming of statemachine HOT 5
- Upgrade to Node 20 HOT 1
- Getting Error While Increasing Power values to 10240 MB HOT 1
- Support for array payload accepting functions HOT 4
- Remove security sensitive lambda:DeleteFunction permission HOT 2
- Log analysis uses Billed Duration rather than Duration for calculating Lambda run time HOT 2
- Image in payload possibility HOT 5
- Bug: Support JSON logging HOT 20
- Missing num error while executing state machine HOT 4
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 aws-lambda-power-tuning.