DEV Community

Cover image for AWS Java Lambda performance optimization
Prabusah
Prabusah

Posted on • Updated 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

Top comments (0)