This is my experience using AWS Lambda with Java and NodeJS – How i solved cold start performance issue.

I was building SaaS application (Web Application) with AWS Cloud Computing.

My first Choice was – Angular 6 -> API Gateway + Lambda (Java) + PostgreSQL

Being 14+ years experience in Java, i preferred Lambda with Java as it is quick for me to develop.
I need all below in one lambda function for specific use case.

1. DynamoDB (as my cache solution, instead of Elastic Cache as i can stay with free 25 RU and 25 WU), to read the session element.
2. PostgreSQL Database connection to insert the data.
3. SES – Email connection to send email

Development went very fast, as Java Maven libraries provide quick way for Integration.

As soon as i deploy Lambda function in AWS, with 1024 MB of memory and 5 seconds timeout.

I hit the road blocks – Stateless & Cold Start. Lambda spins each container for each concurrent thread and no database connection pooling works by default. Also Lambda container takes time to spin up the instance of our code before it starts executing, it is called Cold Start time.

Lambda JAVA Performance:

Using JMeter, i invoked my API with 10 concurrent threads at same time, you can see all the 10 containers took approx 5 to 6 seconds to execute my lambda function.

Below is from Cloudwatch which is clear that, 10 instances of Lambda containers are created to serve 10 concurrent requests.

By Inspecting the logs, i can see all the threads too approx 3 seconds to create DynamoDB connection itself.

After realizing and researching for two days on internet, i realized better i write the same code in NodeJS. So i spent a day and wrote new Lambda Function in NodeJS 8.10 for same use case as explained above.

Lambda NodeJS 8.10 Performance:

Using JMeter i did similar test and results are below, WOW…. NodeJS performed 50% better than java.

Even thought it took 2 sec average, this is with in my timeout settings of 5 seconds. And now i can think of Invoking Lambda functions via Cloudwatch Events for every 10mins to keep the threads warm. But overall i liked switching from Java to NodeJS.

Share this post

[SOLVED] – AWS Lambda Cold start problem using NodeJS vs Java Language
Tagged on:     

One thought on “[SOLVED] – AWS Lambda Cold start problem using NodeJS vs Java Language

  • November 2, 2018 at 7:33 am

    Exceptional job miranjan congratulation


Leave a Reply

Your email address will not be published. Required fields are marked *