Home Java javaTutorial AWS SnapStart - Part Measuring cold and warm starts with Java using Lambda layer (1)

AWS SnapStart - Part Measuring cold and warm starts with Java using Lambda layer (1)

Aug 21, 2024 am 06:08 AM

AWS SnapStart - Part Measuring cold and warm starts with Java using Lambda layer (1)

Introduction

In the blog post How to create, publish and use layers for Java 21 Lambda functions we published our first Lambda layer with Java 21. In this article we'll create the application using this Lambda layer and then measure cold and warm start times without SnapStart enabled, with SnapStart enabled and also applied DynamoDB invocation priming optimization. We’ll also compare the results with our measurements without using the Lambda layers and providing all dependencies in the POM file which we did in the article Measuring cold and warm starts with Java 21 using different Lambda memory settings.

Measuring cold and warm starts with Java 21 using Lambda layer

In our experiment we'll use the sample application. There are basically 2 Lambda functions defined in the AWS SAM template which both respond to the API Gateway requests and retrieve product by id received from the API Gateway from DynamoDB. One Lambda function GetProductByIdWithPureJava21LambdaWithCommonLayer can be used with and without SnapStart and the second one GetProductByIdWithPureJava21LambdaAndPrimingWithCommonLayer uses SnapStart and DynamoDB request invocation priming.

Dependencies provided via the Lambda layer have the scope “provided” in the pom.xml file of our application.

In order to attach the Lambda layer created in the article How to create an publish and use layers for Java 21 Lambda functions for the Lambda functions in the AWS SAM template we have to add Layers parameter to the Lambda function like this:

    Type: AWS::Serverless::Function
    Properties:
      FunctionName: GetProductByIdWithPureJava21LambdaWithCommonLayer
      AutoPublishAlias: liveVersion
      Layers:
        - !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:aws-pure-java-21-common-lambda-layer:1
      Handler: software.amazonaws.example.product.handler.GetProductByIdHandler::handleRequest
Copy after login

Please replace the Layer ARN (including the version) with your own one which is the output of the publish layer command (aws lambda publish-layer-version).

The results of the experiment below were based on reproducing more than 100 cold and approximately 100.000 warm starts with experiment which ran for approximately 1 hour. For it (and experiments from my previous article) I used the load test tool hey, but you can use whatever tool you want, like Serverless-artillery or Postman.
I ran all these experiments by giving our Lambda functions 1024 MB memory and by passing the following compilation option via the environment variable: JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" (client compilation without profiling) which provides a very good trade-off between the cold and warm start times.

In the tables below I'll also provide the results with our measurements without using the Lambda layers taken from the article Measuring cold and warm starts with Java 21 using different Lambda memory settings to directly have the comparison between both.
Abbreviation c is for the cold start and w is for the warm start.

Cold (c) and warm (w) start times without SnapStart in ms:

Experiment 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
with common Lambda Layer 3497.91 3597.18 3695.58 3800.47 3908.33 4011.71 5.82 6.72 8.00 17.97 55.48 1709.13
w/o Lambda Layer 3157.6 3213.85 3270.8 3428.2 3601.12 3725.02 5.77 6.50 7.81 20.65 90.20 1423.63

Cold (c) and warm (w) start times with SnapStart without Priming in ms:

Experiment 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
with common Lambda Layer 2047.12 2124.24 2439.49 2705.52 2735.43 2831.59 5.68 6.40 7.45 17.06 48.45 2139.74
w/o Lambda Layer 1626.69 1741.10 2040.99 2219.75 2319.54 2321.64 5.64 6.41 7.87 21.40 99.81 1355.09

Cold (c) and warm (w) start times with SnapStart and with DynamoDB invocation Priming in ms:

Experiment 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
with common Lambda Layer 713.88 766.38 1141.94 1181.41 1214.94 1215.32 5.59 6.30 7.39 16.39 45.09 574.61
w/o Lambda Layer 702.55 759.52 1038.50 1169.66 1179.05 1179.36 5.73 6.51 7.87 21.75 92.19 328.41

Conclusion

In this article we created the application using the Lambda layer with common dependencies and then measured cold and warm start times without SnapStart enabled, with SnapStart enabled and also applied DynamoDB invocation priming optimization and compared the results with our measurements without using the Lambda layers and providing all dependencies in the POM file which we did in the article Measuring cold and warm starts with Java 21 using different Lambda memory settings.

I’ve performed measurements with the usage of the common Lambda layers multiple times to really confirm the result of my experiment. Even if I had some deviations in the results between those measurements, the trend was always the same: When not enabling SnapStart or enabling it but not using priming of the DynamoDB invocation the cold starts with the usage of common Lambda layer was several hundred milliseconds higher compared to package all dependencies only in the POM file. Only when SnapStart was enabled for the Lambda function and DynamoDB invocation priming was applied the cold starts with both approaches were very close, probably due to the fact that everything was already in the created snapshot.

The warm starts of the Lambda function were quite close for both use cases (with and without the usage of the Lambda layers) and for all experiments (with and without SnapStart enabled) for nearly all percentiles, but I've always got higher results for the maximal value with the usage of common Lambda layer.

In the next article I'll continue my experiments with the Lambda layers. This time I’ll create, publish and use the Lambda layer containing not only common dependencies (like in this article) but all dependencies required to run this application and then compare the results of both experiments.

The above is the detailed content of AWS SnapStart - Part Measuring cold and warm starts with Java using Lambda layer (1). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list? How to use the Redis cache solution to efficiently realize the requirements of product ranking list? Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

See all articles