4

I am invoking lambda_B 22 times(asynchronously) from lambda_A, Single lambda_B call completes execution in 3 sec so according to this when i am invoking 22 lambda asynchronously so it should take time around 3 sec. But its taking time 16-20 sec

Here is sample code i am using

async callingLambda(arrayvalue) {
  try {
    const lambdaResponse = await BPromise.all(
      arrayvalue.map((leg) => {
        return new BPromise((resolve, reject) => {
          const FunctionName = 'Lambda_B';
          lambda.invoke({
            FunctionName: FunctionName,
            InvocationType: 'RequestResponse',
            LogType: 'Tail',
            Payload: JSON.stringify(reqParmaters)
          }, function(error, data) {
            if (error) {
              reject(error);
            } else {
              resolve(body.errors.length ? null : body.data);
            }
          });
        });
      })
    );
    return lambdaResponse;
  } catch (error) {
    return BPromise.reject(error);
  }
}

i have made few observation that is if i decrease no of calls to 4-6 then its take around 3 sec but when i increase the no of calls time is increased as well.

According to my research this issue may be arise due to the no. of I/O operation handled by nodejs parallelly is equal to UV_THREADPOOL_SIZE and default value of UV_THREADPOOL_SIZE is 4.

I have also increase the size of UV_THREADPOOL_SIZE but its not working.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Aabid
  • 953
  • 5
  • 23
  • 1
    It should be noted that it's extraordinarily unlikely that this would take 3 seconds, even in the best case scenario. Your computer likely isn't able to run those all simultaneously, and even if it could it likely won't. 16 seconds is pretty good for a task that would take over a minute if run sequentially. – Carcigenicate Sep 07 '18 at 11:50
  • @Carcigenicate "your computer" doesn't run Lambda functions. – Michael - sqlbot Sep 07 '18 at 22:34
  • "Your computer" runs "lambda" functions when invoking locally, i.e testing. I wonder if it has something to do with the cold-start time of the lambdas? – Brian McCall Sep 08 '18 at 23:35
  • @BrianMcCall I have considered the case of cold-start time, but my lambdas are in warm up state. – Aabid Sep 10 '18 at 05:56
  • @Aabid Can you please check the cluster that could help you `https://stackoverflow.com/questions/43213250/nodejs-cluster-on-aws-lambda` – IftekharDani Sep 11 '18 at 08:49

1 Answers1

0

You have an issue in the params of your invoking process. Reference to AWS: Lambda docs for an async call you have to set

InvocationType: 'Event'

Instead of:

InvocationType: 'RequestResponse'

Take a look at https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html

Nikolay Vetrov
  • 624
  • 6
  • 17