Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lamba with poor performance when using RDS

I've implemented an AWS Lambda function using the Serverless Framework. That Lambda function is using RDS and MongoDB. The MongoDB endpoint runs around 500ms, but RDS runs on 12 sec (cold start) and ~3 sec (hot start).

Note: I am using Sequelize in this endpoint.

How to speed up my RDS Lambda endpoint?

like image 231
alish Avatar asked Feb 16 '17 22:02

alish


1 Answers

On the first line after your functions module definition, add the following line

context.callbackWaitsForEmptyEventLoop = false;

callbackWaitsForEmptyEventLoop

  • The default value is true
  • Useful only to modify the default behavior of the callback.

You can set this property to false to request AWS Lambda to freeze the process soon after the callback is called, even if there are events in the event loop. AWS Lambda will freeze the process, any state data and the events in the Node.js event loop (any remaining events in the event loop processed when the Lambda function is called next and if AWS Lambda chooses to use the frozen process)

More details read this article

like image 96
Niroshan Ranapathi Avatar answered Nov 15 '22 16:11

Niroshan Ranapathi