DEV Community

Cover image for AWS Java Lambda performance optimization
Prabusah
Prabusah

Posted on • Edited on

AWS Java Lambda performance optimization

TL;DR

Add environment variable to AWS Lambda (Java) as below:
Environment variable Name (Key): JAVA_TOOL_OPTIONS
Environment variable Value: -XX:+Tiered Compilation -XX:TieredStopAtLevel=1

Details

AWS Lambda (Java) gets invoked (new execution environment scenario), then cold start time = a new JVM started time + application code loading time.

Let's see how one can reduce JVM start time that could eventually reduce the cold start time using Tiered compilation level of JVM.

Two types of JIT compilers available in the JVM. C1 type of compiler optimized for faster start-up time. Best suitable for short-lived applications. C2 type of compiler optimized for better overall performance. C2 compiler analyzes code for a longer period compared to C1 in order to producer optimized compiled code for better performance.

C1 compiler is best suits the need of AWS Lambda and here's how to instruct Lambda to use C1 compiler. AWS Console -> AWS Lambda service -> Environment variable section add the below key and value. Environment variable Name (Key): JAVA_TOOL_OPTIONS
Environment variable Value: -XX:+Tiered Compilation -XX:TieredStopAtLevel=1

Image by OpenClipart-Vectors from Pixabay

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay