Spring Boot 3 application on AWS Lambda - Part 11 Measuring cold and warm starts of Lambda function using Docker Container Image

Vadym Kazulkin - Sep 16 - - Dev Community

Introduction

In the article How to develop and deploy Lambda function using Docker Container Image and Java (21) runtime I gave step by step introduction about how to develop and deploy Lambda function using Docker container image and Java 21 runtime without using any frameworks. As Docker Container Image is generic format, we can simply take our Spring Cloud Function application introduced in the article Develop application with Spring Cloud Function AWS and deploy it using the same steps. So, I published the re-worked version of this application (adding the Dockerfle and changing the SAM template) to be deployed as a Docker image here. For all Lambda functions we use JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" (which gives a reasonable trade-off between cold and warm start times) and give them 1024 MB memory. The same also works using AWS Serverless Java Container.

Measuring cold and warm starts of Lambda function using Spring Cloud Function and Docker Container Image as deployment format

The results of the experiment below were based on reproducing more than 100 cold and approximately 100.000 warm starts for the duration of 1 hour with Lambda function GetProductByIdWithSpringBootJava21DockerImage which is mapped to the Java Lambda handler class which is responsible for retrieving the product (stored in the DynamoDB) by its id. For it I used the load test tool hey, but you can use whatever tool you want, like Serverless-artillery or Postman.

Cold (c) and warm (m) start time in ms:

c p50 c p75 c p90 c p99 c p99.9 c max w p50 w p75 w p90 w p99 w p99.9 w max
4558.68 4622.92 4749.37 5002.74 7183.64 7185.5 7.16 7.94 9.09 20.99 52.47 1313.08

Conclusion

In this article we measured cold and warms starts of the Lambda function using this approach AWS Lambda base Docker container image. We experienced much higher cold start and slightly higher warm start times compared to the measurement with Lambda function using Docker Container Image and Java (21) runtime without using Spring (Boot) framework but also compared to measuring cold start times with other approaches using Spring Boot: AWS Serverless Java Container, AWS Lambda Adapter and Spring Cloud Functions introduced in the past articles of this series.

AWS Lambda SnapStart which significantly reduces cold start times is currently only available for Java Corretto managed runtimes (11, 17 and 21) and not for Docker container images. You can explore jlink tool to assemble and optimize a set of modules and their dependencies into a smaller custom runtime image and Class data sharing (CDS) though which helps reduce the startup time for Java programming language applications, in particular smaller applications, as well as reduce footprint. The advantage of using the Docker Image as deployment artifact for Java is the ability to use recent Java runtime like Java 23 which will be released in September.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .