简体   繁体   中英

How can I improve the performance of an AWS Lambda Function with NodeJS?

I am currently have a working NodeJS application that generates templated PDFs hosted on AWS Lambda. It takes in handlebars template(s), generates a pdf with the templates and the data, writes the PDF to an S3 bucket an returns the file name. If the file has already exists on S3, it returns the file name of the existing file.

When the file exists, it takes around 3 seconds to complete. If it needs to generate the file, it takes between 15-25 seconds to complete.

I have it configured to have a maximum 128MB of memory and timeout at 25 seconds, but I would really prefer to drop that to 15 seconds if possible. Due to the complexity and length of some of the PDFs that will be generated, I currently have to leave the timeout that long.

Excluding the NodeJS libs that I am using, is there a way that I can speed up Lambda execution and/or Lambda's latency when reading/writing to S3?

One of the easiest ways to get increased performance from your Lambda function is to increase the memory allocated to it. Increasing the memory also increases the amount of CPU allocated to your function and you should see the performance increase correspondingly.

Aside from that, it's down to normal performance tuning techniques you would use with any application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM