I'm trying to run a process launching 1000 lambdas in parallels.
I made a test with 10 lambdas that succeeded in ~4 seconds, however scale up to 1000 lambdas increase the running time to ~23 seconds.
const lambda = new AWS.Lambda();
await Promise.all(
Array(1000)
.fill(0)
.map((_, i) => {
if (i === 0) console.log("start lambda", i, new Date().getSeconds());
if (i === 999) console.log("start lambda", i, new Date().getSeconds());
return lambda
.invoke({
FunctionName: "myFunction",
Payload: JSON.stringify(payload),
})
.promise()
.then((x) => {
if (i === 0) console.log("end lambda", i, new Date().getSeconds());
if (i === 999) console.log("end lambda", i, new Date().getSeconds());
return x;
});
})
);
output
start lambda 0 11
start lambda 999 11
end lambda 0 15
end lambda 999 39
I'm quite surprised about that observation because Lambda is a service designed to be highly scalable. I'd like to understand why is it so slower and what could I do to solve this problem.