Vadym Kazulkin | @VKazulkin |ip.labs GmbH High Performance Serverless Java on AWS Vadym Kazulkin, ip.labs , AWS and Java User Groups, 16 June 2025
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Joint collaboration between User Groups High performance Serverless Java on AWS 2
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Vadym Kazulkin ip.labs GmbH Bonn, Germany Co-Organizer of the Java User Group Bonn v.kazulkin@gmail.com @VKazulkin https://dev.to/vkazulkin https://github.com/Vadym79/ https://de.slideshare.net/VadymKazulkin/ https://www.linkedin.com/in/vadymkazulkin https://www.iplabs.de/ Contact
Vadym Kazulkin | @VKazulkin |ip.labs GmbH About ip.labs High performance Serverless Java on AWS 4
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Java Popularity 5 High performance Serverless Java on AWS Vadym Kazulkin | @VKazulkin | ip.labs GmbH
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 6 High performance Serverless Java on AWS https://distantjob.com/blog/programming-languages-rank/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Life of the Java (Serverless) Developer on AWS 7 High performance Serverless Java on AWS
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Corretto Java 8 ▪ With extended long-term support until 2026 ▪ Coretto Java 11 (since 2019) ▪ Coretto Java 17 (since April 2023) ▪ Corretto Java 21(since November 2023) ▪ Only Long Term Support (LTS) by AWS AWS Java Versions Support High performance Serverless Java on AWS 8
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS People behind Amazon Corretto High performance Serverless Java on AWS 9
Vadym Kazulkin | @VKazulkin |ip.labs GmbH … but serverless adoption of Java looks like this! 10 High performance Serverless Java on AWS Java is a very fast and mature programming language…
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Percent of AWS Lambda Invocations by Language 2021 vs 2023 High performance Serverless Java on AWS 11 https://www.datadoghq.com/state-of-serverless-2021 https://www.datadoghq.com/state-of-serverless/ PHYTON IS THE MOST POPULAR LAMDA RUNTIME
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Developers love Java and will be happy to use it for Serverless applications But what are the challenges ? High performance Serverless Java on AWS 12
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ “cold start” times (latencies) ▪ memory footprint (high cost in AWS) Serverless with Java Challenges High performance Serverless Java on AWS 13
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 14 https://github.com/Vadym79/AWSLambdaJavaSnapStart
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda Basics 15 High performance Serverless Java on AWS
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda High performance Serverless Java on AWS 16 ▪ Runs code without provisioning or managing servers ▪ Runs your code on a high-availability compute infrastructure and manages all the computing resources, including server and operating system maintenance, capacity provisioning, automatic scaling, and logging
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 17 High performance Serverless Java on AWS Challenge No. 1 A Big Cold-Start
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda function lifecycle – a full cold start How to develop, run and optimize Spring Boot 3 application on AWS Lambda 18 Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Creating AWS Lambda with Java runtime High performance Serverless Java on AWS 19 Full CPU access only approx. at 1.8 GB memory allocated
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Start Firecracker VM (execution environment) ▪ AWS Lambda starts the Java runtime ▪ Java runtime loads and initializes Lambda function code (Lambda handler Java class) ▪ Class loading ▪ Static initializer block of the handler class is executed (i.e. AWS service client creation) ▪ Runtime dependency injection ▪ Just-in-Time (JIT) compilation ▪ Lambda invokes the handler method High performance Serverless Java on AWS 20 Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications Michael Hart: „Shave 99.93% off your Lambda bill with this one weird trick“ https://hichaelmart.medium.com/shave-99-93-off-your-lambda-bill-with-this-one-weird-trick-33c0acebb2ea Lambda function lifecycle
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Creating AWS Lambda with Java runtime High performance Serverless Java on AWS 21
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Amazon API Gateway High performance Serverless Java on AWS 22
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Amazon API Gateway High performance Serverless Java on AWS 23
Vadym Kazulkin | @VKazulkin |ip.labs GmbH public class GetProductByIdHandler implements RequestHandler<APIGatewayProxyRequestEvent, Optional<Product>> { private static final ProductDao productDao = new DynamoProductDao(); @Override public Optional<Product> handleRequest(APIGatewayProxyRequestEvent event, Context context) { String id = event.getPathParameters().get("id"); return productDao.getProduct(id); }} AWS Lambda Function with Java runtime How to develop, run and optimize Spring Boot 3 application on AWS Lambda 24 Invocation of the handeRequest method is the warm start
Vadym Kazulkin | @VKazulkin |ip.labs GmbH handleRequest method input High performance Serverless Java on AWS 25 https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Amazon DynamoDB High performance Serverless Java on AWS 26 ▪ Amazon DynamoDB is a serverless, NoSQL, fully managed database with single-digit millisecond performance at any scale.
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 27 https://github.com/Vadym79/AWSLambdaJavaSnapStart ▪ Lambda has 1024 MB memory setting ▪ Lambda uses x86 architecture ▪ Default (Apache) Http Client for communication with DynamoDB ▪ 14 MB artifact size, , all dependencies in the POM file ▪ Java compilation option - XX:+TieredCompilation - XX:TieredStopAtLevel=1 ▪ Info about the experiments: ▪ Approx. 1 hour duration ▪ Approx. first* 100 cold starts ▪ Approx. first 100.000 warm starts *after Lambda function being re-deployed
Vadym Kazulkin | @VKazulkin |ip.labs GmbH https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k Measurements in ms p50 p75 p90 p99 p99.9 max Amazon Corretto Java 21 cold start 3158 3214 3270 3428 3601 3725 Amazon Corretto Java 21 warm start 5,77 6,50 7,81 20,65 90,20 1423,63 Cold and warm starts with Java 21
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Latency is the amount of time it takes from when a request is made by the user to the time it takes for the response to get back to that user Latency How to develop, run and optimize Spring Boot 3 application on AWS Lambda 29
Vadym Kazulkin | @VKazulkin |ip.labs GmbH For our application: Overall latency = t(client to create and send request to the API Gateway endpoint) + t(API Gateway to process request and invoke Lambda function) + t(Lambda cold start time) + t(Lambda warm start time) + t(API Gateway to processes Lambda response and sends it back to the client) + t(client to receive and process response from the API Gateway endpoint) Latency How to develop, run and optimize Spring Boot 3 application on AWS Lambda 30 involves DNS resolve and SSL handshake
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ AWS SnapStart ▪ GraalVM (Native Image) Options To Reduce Cold Start Time High performance Serverless Java on AWS 31
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda SnapStart 32 How to develop, run and optimize Spring Boot 3 application on AWS Lambda
Vadym Kazulkin | @VKazulkin |ip.labs GmbH „AWS Lambda SnapStart „ series How to develop, run and optimize Spring Boot 3 application on AWS Lambda 34 https://dev.to/vkazulkin/series/24979 Article series covers they why and what behind Lambda SnapStart and priming techniques including measurements for cold and warm starts with different settings for ▪ Java 11 ▪ Java 17 ▪ Java 21 ▪ Micronaut ▪ Quarkus ▪ Spring Boot 2.7
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Lambda SnapStart for Java can improve startup performance for latency- sensitive applications ▪ SnapStart is fully managed AWS Lambda SnapStart How to develop, run and optimize Spring Boot 3 application on AWS Lambda 35 https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Currently available for Lambda managed Java Runtimes (Java 11, 17 and 21), Python and .NET ▪ Not available for all other Lambda runtimes: ▪ Docker Container Image ▪ Custom (Lambda) Runtime (a way to ship GraalVM Native Image) AWS Lambda SnapStart 36 https://github.com/Vadym79/AWSLambdaJavaDockerImage/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation 37 https://aws.amazon.com/de/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/ Vadym Kazulkin @VKazulkin , ip.labs GmbH C Create Snapshot Firecracker microVM create & restore snapshot
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Linux CRIU available since 2012 allows a running application to be paused and restarted at some point later in time, potentially on a different machine. ▪ The overall goal of the project is to support the migration of containers. ▪ When performing a checkpoint, essentially, the full context of the process is saved: program counter, registers, stacks, memory-mapped and shared memory ▪ To restore the application, all this data can be reloaded and (theoretically) it continues from the same point. ▪ Challenges ▪ open files ▪ network connections ▪ sudden change in the value of the system clock ▪ time-based caches CRIU (Checkpoint/Restore in Userspace) 38 https://criu.org/Main_Page
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Comparing Firecracker and CRIU snapshotting: ▪ Firecracker snapshotting saves a whole running OS ▪ CRIU snapshotting saves a single process or container ▪ Advantages of the Firecracker snapshot : we don't have to care about file handles because they will be still valid after resume. ▪ Drawbacks the Firecracker snapshot : the need to reseed /dev/random and to sync the system clock. Snapshot /checkpointing and restore Firecracker microVM vs CRIU 39 https://mail.openjdk.org/pipermail/discuss/2021-July/005864.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ CRaC is a JDK project that allows you to start Java programs with a shorter time to first transaction, combined with less time and resources to achieve full code speed. ▪ CRaC effectively takes a snapshot of the Java process (checkpoint) when it is fully warmed up, then uses that snapshot to launch any number of JVMs from this captured state. ▪ CRaC is based on CRIU or on recently released CRaC engine Warp Ideas behind CRaC (Coordinated Restore at Checkpoint) 41 https://www.azul.com/blog/superfast-application-startup-java-on-crac/ https://github.com/CRaC/docs https://foojay.io/today/warp-the-new-crac-engine/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation How to develop, run and optimize Spring Boot 3 application on AWS Lambda 42 https://dev.to/vkazulkin/measuring-java-11-lambda-cold-starts-with-snapstart-part-1-first-impressions-30a4 https://aws.amazon.com/de/blogs/compute/using-aws-lambda-snapstart-with-infrastructure-as-code-and-ci-cd-pipelines/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Deployment Phase 43 https://dev.to/vkazulkin/measuring-java-11-lambda-cold-starts-with-snapstart-part-1-first-impressions-30a4
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Invocation Phase 44 https://dev.to/vkazulkin/measuring-java-11-lambda-cold-starts-with-snapstart-part-1-first-impressions-30a4
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda SnapStart with Priming 45
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Pre-load as many Java classes as possible before the SnapStart takes the snapshot ▪ Java loads classes on demand (lazy-loading) ▪ Pre-initialize as much as possible before the SnapStart takes the snapshot ▪ Http Clients (Apache, UrlConnection) and JSON Marshallers (Jackson) require expensive one-time initialization per (Lambda) lifecycle. They both are used when creating Amazon DynamoDbClient Ideas behind priming 46
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation High performance Serverless Java on AWS 47 https://aws.amazon.com/de/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/ Vadym Kazulkin @VKazulkin , ip.labs GmbH Lambda uses the CRaC APIs for runtime hooks for Priming C Create Snapshot Firecracker microVM create & restore snapshot
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Prime dependencies during initialization phase (when it worth doing) ▪ „Fake“ the calls to pre-initialize „some other expensive stuff“ (this technique is called Priming) ▪ In case of DynamoDB client put the following code outside of the handler method to pre-initialize the HTTP Client and Jackson Marshaller: DynamoDbClient client = DynamoDbClientBuilder.builder().region(Regions.US_WEST_2).build(); GetItemResponse getItemResponse = client.getItem(GetItemRequest.builder() .key(Map.of("PK", AttributeValue.builder().s(id).build())) .tableName(PRODUCT_TABLE_NAME).build()); …… Best Practices & Recommendations How to develop, run and optimize Spring Boot 3 application on AWS Lambda 48 invocation forces HTTP Client and Jackson Marshallers to pre-initialize getProductById (int id) method
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Enabled with Java Priming High performance Serverless Java on AWS 49 https://dev.to/aws-builders/measuring-java-11-lambda-cold-starts-with-snapstart-part-5-priming-end-to-end-latency-and-deployment-time-jem <dependency> <groupId>io.github.crac</groupId> <artifactId>org-crac</artifactId> <version>0.1.3</version> </dependency> if a refer to Priming in this talk, I mean concretely DynamoDB request invocation priming
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda SnapStart Priming Guide High performance Serverless Java on AWS 50 guide aims to explain techniques for priming Java applications. It assumes a base understanding of AWS Lambda, Lambda SnapStart, and CRaC. https://github.com/marksailes/snapstart-priming-guide
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 p50 p75 p90 p99 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0,00 5,00 10,00 15,00 20,00 25,00 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Warm starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client compilation - XX:+TieredCompilation -XX:TieredStopAtLevel=1 p50 p75 p90 p99 https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 200 400 600 800 1000 1200 1400 1600 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Warm starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client compilation - XX:+TieredCompilation -XX:TieredStopAtLevel=1 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 54 https://github.com/Vadym79/AWSLambdaJavaSnapStart ▪ Lambda has 1024 MB memory setting ▪ Lambda uses x86 architecture ▪ Default (Apache) Http Client for communication with DynamoDB ▪ 18 MB artifact size, , all dependencies in the POM file ▪ Java compilation option - XX:+TieredCompilation - XX:TieredStopAtLevel=1 ▪ Info about the experiments: ▪ Approx. 1 hour duration ▪ Approx. first* 100 cold starts ▪ Approx. first 100.000 warm starts *after Lambda function being re-deployed
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda Memory Setting High performance Serverless Java on AWS 55 ONE SECOND ONE GB
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime for different memory settings p90 256 MB 512 MB 768 MB 1024 MB 1536 MB 2048 MB https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Java Compilation High performance Serverless Java on AWS 66 https://www.geeksforgeeks.org/what-are-the-roles-of-java-compiler-and-interpreter/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Java Compilation Options High performance Serverless Java on AWS 67 Mark Sailes: "Optimizing AWS Lambda function performance for Java” https://aws.amazon.com/de/blogs/compute/optimizing-aws-lambda-function-performance-for-java/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 1000 2000 3000 4000 5000 6000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime using different compilation options for p90 Tiered StopAtLevel 1 StopAtLevel 2 StopAtLevel 3 StopAtLevel 4 https://dev.to/aws-builders/aws-snapstart-part-14-measuring-cold-and-warm-starts-with-java-21-using-different-compilation-options-el4 ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0,00 2,00 4,00 6,00 8,00 10,00 12,00 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Warm starts of Lambda function with Java 21 runtime using different compilation options for p90 Tiered StopAtLevel 1 StopAtLevel 2 StopAtLevel 3 StopAtLevel 4 https://dev.to/aws-builders/aws-snapstart-part-14-measuring-cold-and-warm-starts-with-java-21-using-different-compilation-options-el4 ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Java Garbage Collection Algorithms High performance Serverless Java on AWS 70 • Tested with default GC algorithms settings • G1 default GC produces the best results for cold and warm starts without and with SnapStart (and priming) followed by : • Parallel GC • Shenandoah GC • Couldn‘t make it work with ZGC (generational) GC
Vadym Kazulkin | @VKazulkin |ip.labs GmbH JEP 318: Epsilon: A No-Op Garbage Collector (Experimental) High performance Serverless Java on AWS 71 https://openjdk.org/jeps/318
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda Architecture High performance Serverless Java on AWS 72 https://www.partitionwizard.com/partitionmanager/arm64-vs-x64.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda x86_64 vs arm64 architecture High performance Serverless Java on AWS 74 https://aws.amazon.com/lambda/pricing/?nc1=h_ls For the same memory setting Lambda and Lambda function execution duration the choice of arm64 over x86_64 architecture is approx. 25% cheaper
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 4500 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Cold starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 for p90 x86_64 arm64 ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2 +8,6% +23,9% +24,8%
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 6,40 6,60 6,80 7,00 7,20 7,40 7,60 7,80 8,00 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Warm starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 for p90 x86_64 arm64 ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2 +9,1% +10,1% +4,8%
Vadym Kazulkin | @VKazulkin |ip.labs GmbH HTTP Clients to connect to DynamoDB High performance Serverless Java on AWS 77
Vadym Kazulkin | @VKazulkin |ip.labs GmbH DynamoDbClient client = DynamoDbClient.builder().region(Region.EU_CENTRAL_1) . httpClient(ApacheHttpClient.create()) //.httpClient(UrlConnectionHttpClient.create()) //.httpClient(AwsCrtHttpClient.create()) .build(); Add dependency to the synchronous HTTP Client in use to pom.xml, i.e. <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>aws-crt-client</artifactId> </dependency> Setting synchronous DynamoDB Client High performance Serverless Java on AWS 78
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Cold starts of Lambda function with Java 21 runtime and StopAtLevel 1 compilation and different synchronous HTTP Clients for p90 URL Connection Apache AWS CRT https://dev.to/aws-builders/aws-snapstart-part-15-measuring-cold-and-warm-starts-with-java-21-using-different-synchronous-http-clients-579o ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH DynamoDbAsyncClient dynamoAsyncDbClient = DynamoDbAsyncClient.builder().region(Region.EU_CENTRAL_1) . httpClient(NettyNioAsyncHttpClient.create()) //.httpClient(AwsCrtAsyncHttpClient.create()) .build(); CompletableFuture<GetItemResponse> getItemReponseAsync = dynamoAsyncDbClient.getItem(GetItemRequest.builder(). key(Map.of("PK",AttributeValue.builder(). s(id).build())).tableName(PRODUCT_TABLE_NAME).build()); GetItemResponse getItemResponse = getItemReponseAsync.join(); Setting asynchronous DynamoDB Client High performance Serverless Java on AWS 81
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Add dependency to the asynchronous HTTP Client in use to pom.xml, i.e. <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>netty-nio-client</artifactId> </dependency> Setting asynchronous DynamoDB Client High performance Serverless Java on AWS 82
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Cold starts of Lambda function with Java 21 runtime and StopAtLevel 1 compilation and different asynchronous HTTP Clients for p90 NettyNio AWS CRT ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0,00 2,00 4,00 6,00 8,00 10,00 12,00 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Warm starts of Lambda function with Java 21 runtime and StopAtLevel 1 compilation and different asynchronous HTTP Clients for p90 NettyNio AWS CRT ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2
Vadym Kazulkin | @VKazulkin |ip.labs GmbH HTTP client recommendations High performance Serverless Java on AWS 85 https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/http-configuration.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda Deployment Artifact Size High performance Serverless Java on AWS 86
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 4500 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime using deployment artifact sizes for p90 p90 small p90 medium p90 big ms https://dev.to/aws-builders/aws-snapstart-part-11-measuring-cold-starts-with-java-21-using-different-deployment-artifact-sizes-4g29 ▪ Small -137 KB (“Hello World”) ▪ Medium – 14 MB (our sample application) ▪ Big -50 MB (our sample application + additional dependencies other to AWS services)
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Less (dependencies, classes) is more ▪ Include only required dependencies (e.g. not the whole AWS SDK 2.0 for Java, but the dependencies to the clients to be used in Lambda) ▪ Exclude dependencies, which you don‘t need at runtime i.e. test frameworks like Junit Best Practices & Recommendations High performance Serverless Java on AWS 88 <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.4.2</version> <scope>test</scope> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> <version>2.22.2</version> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.22.2</version> <type>pom</type> <scope>import</scope> </dependency>
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Exclude unused HTTP Client dependencies High performance Serverless Java on AWS 89 <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> <exclusions> <exclusion> <groupId>software.amazon.awssdk</groupId> <artifactId>netty-nio-client</artifactId> </exclusion> <!-- <exclusion> <groupId>software.amazon.awssdk</groupId> <artifactId>apache-client</artifactId> </exclusion> --> </exclusions> </dependency>
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS CRT HTTP Client High performance Serverless Java on AWS 90
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS CRT HTTP Client for Linux High performance Serverless Java on AWS 91 In Linux folder:
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Exclude unused AWS CRT HTTP Client platform dependencies High performance Serverless Java on AWS 92 <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>aws-crt-client</artifactId> <exclusions> <exclusion> <groupId>software.amazon.awssdk.crt</groupId> <artifactId>aws-crt</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>software.amazon.awssdk.crt</groupId> <artifactId>aws-crt</artifactId> <classifier>linux-x86_64</classifier> </dependency> https://github.com/awslabs/aws-crt-java?tab=readme-ov-file#platform-specific-jars
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 93 https://github.com/Vadym79/AWSLambdaJavaSnapStart ▪ Lambda has 1024 MB memory setting ▪ Lambda uses x86 architecture ▪ Default (Apache) Http Client for communication with DynamoDB ▪ 14 MB artifact size, all dependencies in the POM file ▪ Java compilation option - XX:+TieredCompilation - XX:TieredStopAtLevel=1 ▪ Info about the experiments: ▪ Approx. 1 hour duration ▪ Approx. first* 100 cold starts ▪ Approx. first 100.000 warm starts *after Lambda function being re-deployed
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation High performance Serverless Java on AWS 94 https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html https://aws.amazon.com/de/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/ Firecracker microVM create & restore snapshot
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart tiered cache How to develop, run and optimize Spring Boot 3 application on AWS Lambda 95 https://dev.to/aws-builders/aws-snapstart-part-17-impact-of-the-snapshot-tiered-cache-on-the-cold-starts-with-java-21-52ef • Due to the effect of snapshot tiered cache, cold start times reduces with the number of invocations • After certain number of invocations reached the cold start times becomes stable
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda under the Hood High performance Serverless Java on AWS 96 https://www.infoq.com/articles/aws-lambda-under-the-hood/ https://www.infoq.com/presentations/aws-lambda-arch/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 with SnapStart w/o Primingwith SnapStart w/o Priming (last 70) with SnapStart with Priming with SnapStart with Priming (last 70) Cold starts of all approx.100 and last 70 Lambda functions with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 p50 p75 p90 p99 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-17-impact-of-the-snapshot-tiered-cache-on-the-cold-starts-with-java-21-52ef Due to the effect of snapshot tiered cache, cold start times reduces with the number of invocations ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda Profiler Extension for Java High performance Serverless Java on AWS 98 https://github.com/aws/aws-lambda-java-libs/tree/main/experimental/aws-lambda-java-profiler
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda Implementation High performance Serverless Java on AWS 99
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda Profiler Extension for Java High performance Serverless Java on AWS 100 https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format https://github.com/aws/aws-lambda-java-libs/tree/main/experimental/aws-lambda-java-profiler
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Full Priming including APIGatewayProxyRequestEvent Deserialization High performance Serverless Java on AWS 101 https://dev.to/aws-heroes/aws-lambda-profiler-extension-for-java-part-2-improving-lambda-performance-with-lambda-snapstart-4p06
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Full Priming including APIGatewayProxyRequestEvent High performance Serverless Java on AWS 102 This priming technique leads to approx. 20% reduction of the cold start times vs. DynamoDB request priming alone
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS SnapStart Pricing 103 https://aws.amazon.com/lambda/pricing/?nc1=h_ls
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ SnapStart supports the Java 11, 17 and 21 (Corretto), Python and .NET managed runtime only ▪ Deployment with SnapStart enabled takes more than 2-2,5 minutes additionally ▪ Snapshot is deleted from cache if Lambda function is not invoked for 14 days ▪ SnapStart currently does not support : ▪ Provisioned concurrency ▪ Amazon Elastic File System (Amazon EFS) ▪ Ephemeral storage greater than 512 MB AWS SnapStart Challenges & Limitations 104 https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Avoid saving state that depends on uniqueness during initialization ▪ Avoid UUID uniqueSandboxId = UUID.randomUUID() or long envCreationTime = System.currentTimeMillis() im Lambda constructor ▪ Use cryptographically secure pseudorandom number generators ▪ Software that always gets random numbers from /dev/random or /dev/urandom also maintains randomness with SnapStart. ▪ Use java.security.SecureRandom instead of new Random() ▪ Avoid logic relying on time-based caches AWS SnapStart Challenges around uniqueness 105 https://docs.aws.amazon.com/lambda/latest/dg/snapstart-uniqueness.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda SnapStart Bug Scanner 106 https://github.com/aws/aws-lambda-snapstart-java-rules • Does recognize the usage of: • UUID.randomUUID() • System.currentTimeMillis() • new Random() • Doesn’t recognize the usage of: • LocalDate*, LocalTime, ZonedDateTime APIs • Time-base cache frameworks like Google Guava and ExpiringMap from net.jodah
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Perform Priming out of the box without writing the logic on our own ▪ If snapshot not found do regular cold start and create snapshot under the hood ▪ Snapshot creation on first Lambda function invocation instead of during the deployment phase ▪ Regular cold start as long as the snapshot hasn’t been fully taken ▪ Trade off between duration of the deployment phase and several regular bigger cold starts until the snapshot is taken and SnapStart becomes effective (and therefore much shorter cold starts) AWS SnapStart Possible Next Steps High performance Serverless Java on AWS 107 https://dev.to/aws-builders/reducing-cold-starts-on-aws-lambda-with-java-runtime-future-ideas-about-snapstart-graalvm-and-co-3a1b
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 108 High performance Serverless Java on AWS
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ Low footprint ahead-of-time mode for JVM-based languages ▪ High performance for all languages ▪ Convenient language interoperability and polyglot tooling GraalVM Goals High performance Serverless Java on AWS 109 Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
Vadym Kazulkin | @VKazulkin |ip.labs GmbH GraalVM Architecture High performance Serverless Java on AWS 110
Vadym Kazulkin | @VKazulkin |ip.labs GmbH GraalVM Ahead-of-Time Compilation High performance Serverless Java on AWS 111 Source: Oleg Šelajev, Thomas Wuerthinger, Oracle: “Deep dive into using GraalVM for Java and JavaScript” https://www.youtube.com/watch?v=a-XEZobXspo
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AOT vs JIT High performance Serverless Java on AWS 112 Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Promise: Java Function compiled into a native executable using GraalVM Native Image significantly reduces ▪ “cold start” times ▪ memory footprint GraalVM Native Image 113
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ AWS doesn’t provide GraalVM (Native Image) as Java Runtime out of the box ▪ AWS provides Custom Runtime Option Current Challenges with Native Executable using GraalVM High performance Serverless Java on AWS 114
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Custom Lambda Runtimes High performance Serverless Java on AWS 115 https://github.com/Vadym79/AWSLambdaGraalVMNativeImage
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming GraalVM 23 Native Image p50 p75 p90 p99 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0,00 5,00 10,00 15,00 20,00 25,00 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming GraalVM 23 Native Image p50 p75 p90 p99 https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 200 400 600 800 1000 1200 1400 1600 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming GraalVM Native Image 23 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda Memory Setting for Custom Runtime (GraalVM Native Image) High performance Serverless Java on AWS 121 ONE SECOND ONE GB
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 0 200 400 600 800 1000 1200 256 MB 512 MB 768 MB 1024 MB 1280 MB 1536 MB Cold starts of Lambda function with GraalVM 21 Native Image for different memory settings p50 p75 p90 p99 p99.9 max https://github.com/Vadym79/AWSLambdaGraalVMNativeImage/tree/master/pure-lambda-graalvm-jdk-21-native-image ms
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Other optimizations 125 AWS CRT Client supports GraalVM Native Image DynamoDbClient client = DynamoDbClient.builder(). region(Region.EU_CENTRAL_1) ..httpClient(AwsCrtHttpClient.create()) .build(); https://aws.amazon.com/de/blogs/developer/aws-crt-client-for-java-adds-graalvm-native-image-support/ https://dev.to/aws-heroes/lambda-function-with-graalvm-native-image-part-6-measuring-cold-and-warm-starts-with-graalvm-23-4d3a
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Frameworks and libraries Ready for GraalVM Native Image High performance Serverless Java on AWS 126 https://www.graalvm.org/native-image/libraries-and-frameworks/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ You can run into errors when application is running Complex GraalVM Native Image configuration High performance Serverless Java on AWS 127 https://github.com/Vadym79/AWSLambdaGraalVMNativeImage/blob/master/pure-lambda-graalvm-jdk-21-native-image/src/main/reflect.json
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Complex GraalVM Native Image configuration High performance Serverless Java on AWS 128
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Particulary logging configuration in GraalVM Native Image is complex High performance Serverless Java on AWS 129
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Log4j natively supports GraalVM Native since 2.0.25 High performance Serverless Java on AWS 130 https://logging.staged.apache.org/log4j/2.x/graalvm.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Assisted Configuration with GraalVM Tracing Agent High performance Serverless Java on AWS 131 https://www.graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/ https://www.graalvm.org/latest/reference-manual/native-image/guides/configure-with-tracing-agent/ Run the GraalVM tracing agent during the execution of your tests
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ GraalVM is really powerful and has a lot of potential ▪ GraalVM Native Image improves cold starts and memory footprint significantly ▪ GraalVM Native Image is currently not without challenges ▪ Complex GraalVM Native Image configuration files ▪ AWS Lambda Custom Runtime requires Linux executable only ▪ Building Custom Runtime requires some additional effort ▪ e.g. you need a scalable CI/CD pipeline to build memory-intensive native image ▪ Build time is a factor ▪ You need to carefully test to avoid runtime errors GraalVM Conclusion 132
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Lambda Proactive Initialization High performance Serverless Java on AWS 134 In June 2023 AWS updated the documentation for the Lambda Function lifecycle and included this new statement: for functions using unreserved (on-demand) concurrency, Lambda may proactively initialize a function instance, even if there's no invocation. When this happens, you can observe an unexpected time gap between your function's initialization and invocation phases. This gap can appear similar to what you would observe when using provisioned concurrency. https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html https://aaronstuyvenberg.com/posts/understanding-proactive-initialization Running this query over several days across multiple runtimes and invocation methods, between 50% and 75% of initializations were proactive (versus 50% to 25% which were true cold starts)
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Database Choice DynamoDB Aurora Aurora Serverless vs vs
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea DynamoDB DynamoDB + DAX Investment in Knowledge • Understanding of NoSQL databases • Understanding of single-table design principles Same Requires to put Lambda into the VPC to access the database DynamoDB
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea Aurora (Serverless v2) + RDS Proxy Aurora (Serverless v2) + Data API Investment in Knowledge Relational databases are familiar to many developers Same Engine Support MySQL and PostgreSQL MySQL and PostgreSQL Code re-use Yes, only endpoint changes No, requires code re-write Requires to put Lambda into the VPC to access the database https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.Aurora_Fea_Regions_DB-eng.Feature.ServerlessV2.html https://dev.to/aws-builders/data-api-for-amazon-aurora-serverless-v2-with-aws-sdk-for-java-part-1-introduction-and-set-up-of-the-sample-application-3g71 Aurora (Serverless v2 )
Vadym Kazulkin | @VKazulkin |ip.labs GmbH “Data API for Amazon Aurora Serverless v2 with AWS SDK for Java” series High performance Serverless Java on AWS 139 Article series also covers cold and warm start time measurements and optimization techniques https://dev.to/vkazulkin/series/26067
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Database Choice DynamoDB Aurora Aurora Serverless vs vs vs Aurora DSQL
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea • Amazon Aurora DSQL the fastest serverless distributed SQL database • It offers virtually unlimited scale, highest availability, and zero infrastructure management. • It can scale to meet any workload demand without database sharding operational burden of patching, upgrades, maintenance downtime, and more. • With its active-active distributed architecture, Aurora DSQL is designed for 99.99% availability in single-Region configuration and 99.999% in multi-Region configuration, with an innovative active-active, distributed architecture Adding Aurora DSQL into the mix https://aws.amazon.com/blogs/database/introducing-amazon-aurora-dsql/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Unsupported PostgreSQL features in Aurora DSQL High performance Serverless Java on AWS 142 https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-unsupported-features.html
Vadym Kazulkin | @VKazulkin |ip.labs GmbH AWS Lambda with Java managed runtime and Aurora DSQL as a database High performance Serverless Java on AWS 143 ▪ First example using PgJDBC and Hikari datasource pool commited ▪ Lambda performance measurements with/without SnapStart and priming and GraalVM Native Image will follow ▪ With pure Java JDBC API and ORM framework like Hibernate ▪ With single and multi-region Aurora DSQL cluster ▪ Article series with step by step instructions will follow as well https://github.com/Vadym79/AWSLambdaJavaWithAmazonDSQL/tree/main
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Experiment with: ▪ Lambda memory settings ▪ Java compilation options ▪ HTTP Client implementations (sync and async) ▪ Lambda architecture ▪ Lambda SnapStart (with priming techniques) and GraalVM Native Image To find the right trade-off between Lambda cost and performance for your particular use case Wrap up How to develop, run and optimize Spring Boot 3 application on AWS Lambda 145
Vadym Kazulkin | @VKazulkin |ip.labs GmbH ▪ With AWS SnapStart and GraalVM Native Image you can reduce cold start times of the AWS Lambda with Java 21 runtime to the acceptable values ▪ If you’re willing to accept slightly higher cold and warm start times for certain the Lambda function(s) and solid priming is applicable -> use fully managed AWS SnapStart with priming ▪ If a very high performance for certain the Lambda function(s) is really crucial for your business -> go for GraalVM Native Image Wrap up and personal suggestions How to develop, run and optimize Spring Boot 3 application on AWS Lambda 146
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Project Leyden High performance Serverless Java on AWS 147 The primary goal of this Project is to improve the startup time, time to peak performance, and footprint of Java programs. https://www.youtube.com/watch?v=teXijm79vno https://openjdk.org/projects/leyden/
Vadym Kazulkin | @VKazulkin |ip.labs GmbH Word of caution High performance Serverless Java on AWS 148 Re-measure for your use case! Even with my examples measurements might already produce different results due to: ▪ Lambda Amazon Corretto Java 21 managed runtime minor version changes ▪ Lambda SnapStart snapshot create and restore improvements ▪ Firecracker VM improvements ▪ GraalVM (major and minor version) and Native Image improvements ▪ There are still servers behind Lambda ▪ Java Memory Model impact (L or RAM caches hits and misses)
Vadym Kazulkin | @VKazulkin |ip.labs GmbH 149 High performance Serverless Java on AWS Thank you

High performance Serverless Java on AWS-AWS and Java User Group Vienna 2025

  • 1.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH High Performance Serverless Java on AWS Vadym Kazulkin, ip.labs , AWS and Java User Groups, 16 June 2025
  • 2.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Joint collaboration between User Groups High performance Serverless Java on AWS 2
  • 3.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Vadym Kazulkin ip.labs GmbH Bonn, Germany Co-Organizer of the Java User Group Bonn v.kazulkin@gmail.com @VKazulkin https://dev.to/vkazulkin https://github.com/Vadym79/ https://de.slideshare.net/VadymKazulkin/ https://www.linkedin.com/in/vadymkazulkin https://www.iplabs.de/ Contact
  • 4.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH About ip.labs High performance Serverless Java on AWS 4
  • 5.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Java Popularity 5 High performance Serverless Java on AWS Vadym Kazulkin | @VKazulkin | ip.labs GmbH
  • 6.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 6 High performance Serverless Java on AWS https://distantjob.com/blog/programming-languages-rank/
  • 7.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Life of the Java (Serverless) Developer on AWS 7 High performance Serverless Java on AWS
  • 8.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Corretto Java 8 ▪ With extended long-term support until 2026 ▪ Coretto Java 11 (since 2019) ▪ Coretto Java 17 (since April 2023) ▪ Corretto Java 21(since November 2023) ▪ Only Long Term Support (LTS) by AWS AWS Java Versions Support High performance Serverless Java on AWS 8
  • 9.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS People behind Amazon Corretto High performance Serverless Java on AWS 9
  • 10.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH … but serverless adoption of Java looks like this! 10 High performance Serverless Java on AWS Java is a very fast and mature programming language…
  • 11.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Percent of AWS Lambda Invocations by Language 2021 vs 2023 High performance Serverless Java on AWS 11 https://www.datadoghq.com/state-of-serverless-2021 https://www.datadoghq.com/state-of-serverless/ PHYTON IS THE MOST POPULAR LAMDA RUNTIME
  • 12.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Developers love Java and will be happy to use it for Serverless applications But what are the challenges ? High performance Serverless Java on AWS 12
  • 13.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ “cold start” times (latencies) ▪ memory footprint (high cost in AWS) Serverless with Java Challenges High performance Serverless Java on AWS 13
  • 14.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 14 https://github.com/Vadym79/AWSLambdaJavaSnapStart
  • 15.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda Basics 15 High performance Serverless Java on AWS
  • 16.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda High performance Serverless Java on AWS 16 ▪ Runs code without provisioning or managing servers ▪ Runs your code on a high-availability compute infrastructure and manages all the computing resources, including server and operating system maintenance, capacity provisioning, automatic scaling, and logging
  • 17.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 17 High performance Serverless Java on AWS Challenge No. 1 A Big Cold-Start
  • 18.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda function lifecycle – a full cold start How to develop, run and optimize Spring Boot 3 application on AWS Lambda 18 Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications
  • 19.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Creating AWS Lambda with Java runtime High performance Serverless Java on AWS 19 Full CPU access only approx. at 1.8 GB memory allocated
  • 20.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Start Firecracker VM (execution environment) ▪ AWS Lambda starts the Java runtime ▪ Java runtime loads and initializes Lambda function code (Lambda handler Java class) ▪ Class loading ▪ Static initializer block of the handler class is executed (i.e. AWS service client creation) ▪ Runtime dependency injection ▪ Just-in-Time (JIT) compilation ▪ Lambda invokes the handler method High performance Serverless Java on AWS 20 Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications Michael Hart: „Shave 99.93% off your Lambda bill with this one weird trick“ https://hichaelmart.medium.com/shave-99-93-off-your-lambda-bill-with-this-one-weird-trick-33c0acebb2ea Lambda function lifecycle
  • 21.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Creating AWS Lambda with Java runtime High performance Serverless Java on AWS 21
  • 22.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Amazon API Gateway High performance Serverless Java on AWS 22
  • 23.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Amazon API Gateway High performance Serverless Java on AWS 23
  • 24.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH public class GetProductByIdHandler implements RequestHandler<APIGatewayProxyRequestEvent, Optional<Product>> { private static final ProductDao productDao = new DynamoProductDao(); @Override public Optional<Product> handleRequest(APIGatewayProxyRequestEvent event, Context context) { String id = event.getPathParameters().get("id"); return productDao.getProduct(id); }} AWS Lambda Function with Java runtime How to develop, run and optimize Spring Boot 3 application on AWS Lambda 24 Invocation of the handeRequest method is the warm start
  • 25.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH handleRequest method input High performance Serverless Java on AWS 25 https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
  • 26.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Amazon DynamoDB High performance Serverless Java on AWS 26 ▪ Amazon DynamoDB is a serverless, NoSQL, fully managed database with single-digit millisecond performance at any scale.
  • 27.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 27 https://github.com/Vadym79/AWSLambdaJavaSnapStart ▪ Lambda has 1024 MB memory setting ▪ Lambda uses x86 architecture ▪ Default (Apache) Http Client for communication with DynamoDB ▪ 14 MB artifact size, , all dependencies in the POM file ▪ Java compilation option - XX:+TieredCompilation - XX:TieredStopAtLevel=1 ▪ Info about the experiments: ▪ Approx. 1 hour duration ▪ Approx. first* 100 cold starts ▪ Approx. first 100.000 warm starts *after Lambda function being re-deployed
  • 28.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k Measurements in ms p50 p75 p90 p99 p99.9 max Amazon Corretto Java 21 cold start 3158 3214 3270 3428 3601 3725 Amazon Corretto Java 21 warm start 5,77 6,50 7,81 20,65 90,20 1423,63 Cold and warm starts with Java 21
  • 29.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Latency is the amount of time it takes from when a request is made by the user to the time it takes for the response to get back to that user Latency How to develop, run and optimize Spring Boot 3 application on AWS Lambda 29
  • 30.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH For our application: Overall latency = t(client to create and send request to the API Gateway endpoint) + t(API Gateway to process request and invoke Lambda function) + t(Lambda cold start time) + t(Lambda warm start time) + t(API Gateway to processes Lambda response and sends it back to the client) + t(client to receive and process response from the API Gateway endpoint) Latency How to develop, run and optimize Spring Boot 3 application on AWS Lambda 30 involves DNS resolve and SSL handshake
  • 31.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ AWS SnapStart ▪ GraalVM (Native Image) Options To Reduce Cold Start Time High performance Serverless Java on AWS 31
  • 32.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda SnapStart 32 How to develop, run and optimize Spring Boot 3 application on AWS Lambda
  • 33.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH „AWS Lambda SnapStart „ series How to develop, run and optimize Spring Boot 3 application on AWS Lambda 34 https://dev.to/vkazulkin/series/24979 Article series covers they why and what behind Lambda SnapStart and priming techniques including measurements for cold and warm starts with different settings for ▪ Java 11 ▪ Java 17 ▪ Java 21 ▪ Micronaut ▪ Quarkus ▪ Spring Boot 2.7
  • 34.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Lambda SnapStart for Java can improve startup performance for latency- sensitive applications ▪ SnapStart is fully managed AWS Lambda SnapStart How to develop, run and optimize Spring Boot 3 application on AWS Lambda 35 https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
  • 35.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Currently available for Lambda managed Java Runtimes (Java 11, 17 and 21), Python and .NET ▪ Not available for all other Lambda runtimes: ▪ Docker Container Image ▪ Custom (Lambda) Runtime (a way to ship GraalVM Native Image) AWS Lambda SnapStart 36 https://github.com/Vadym79/AWSLambdaJavaDockerImage/
  • 36.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation 37 https://aws.amazon.com/de/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/ Vadym Kazulkin @VKazulkin , ip.labs GmbH C Create Snapshot Firecracker microVM create & restore snapshot
  • 37.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Linux CRIU available since 2012 allows a running application to be paused and restarted at some point later in time, potentially on a different machine. ▪ The overall goal of the project is to support the migration of containers. ▪ When performing a checkpoint, essentially, the full context of the process is saved: program counter, registers, stacks, memory-mapped and shared memory ▪ To restore the application, all this data can be reloaded and (theoretically) it continues from the same point. ▪ Challenges ▪ open files ▪ network connections ▪ sudden change in the value of the system clock ▪ time-based caches CRIU (Checkpoint/Restore in Userspace) 38 https://criu.org/Main_Page
  • 38.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Comparing Firecracker and CRIU snapshotting: ▪ Firecracker snapshotting saves a whole running OS ▪ CRIU snapshotting saves a single process or container ▪ Advantages of the Firecracker snapshot : we don't have to care about file handles because they will be still valid after resume. ▪ Drawbacks the Firecracker snapshot : the need to reseed /dev/random and to sync the system clock. Snapshot /checkpointing and restore Firecracker microVM vs CRIU 39 https://mail.openjdk.org/pipermail/discuss/2021-July/005864.html
  • 39.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ CRaC is a JDK project that allows you to start Java programs with a shorter time to first transaction, combined with less time and resources to achieve full code speed. ▪ CRaC effectively takes a snapshot of the Java process (checkpoint) when it is fully warmed up, then uses that snapshot to launch any number of JVMs from this captured state. ▪ CRaC is based on CRIU or on recently released CRaC engine Warp Ideas behind CRaC (Coordinated Restore at Checkpoint) 41 https://www.azul.com/blog/superfast-application-startup-java-on-crac/ https://github.com/CRaC/docs https://foojay.io/today/warp-the-new-crac-engine/
  • 40.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation How to develop, run and optimize Spring Boot 3 application on AWS Lambda 42 https://dev.to/vkazulkin/measuring-java-11-lambda-cold-starts-with-snapstart-part-1-first-impressions-30a4 https://aws.amazon.com/de/blogs/compute/using-aws-lambda-snapstart-with-infrastructure-as-code-and-ci-cd-pipelines/
  • 41.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Deployment Phase 43 https://dev.to/vkazulkin/measuring-java-11-lambda-cold-starts-with-snapstart-part-1-first-impressions-30a4
  • 42.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Invocation Phase 44 https://dev.to/vkazulkin/measuring-java-11-lambda-cold-starts-with-snapstart-part-1-first-impressions-30a4
  • 43.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda SnapStart with Priming 45
  • 44.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Pre-load as many Java classes as possible before the SnapStart takes the snapshot ▪ Java loads classes on demand (lazy-loading) ▪ Pre-initialize as much as possible before the SnapStart takes the snapshot ▪ Http Clients (Apache, UrlConnection) and JSON Marshallers (Jackson) require expensive one-time initialization per (Lambda) lifecycle. They both are used when creating Amazon DynamoDbClient Ideas behind priming 46
  • 45.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation High performance Serverless Java on AWS 47 https://aws.amazon.com/de/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/ Vadym Kazulkin @VKazulkin , ip.labs GmbH Lambda uses the CRaC APIs for runtime hooks for Priming C Create Snapshot Firecracker microVM create & restore snapshot
  • 46.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Prime dependencies during initialization phase (when it worth doing) ▪ „Fake“ the calls to pre-initialize „some other expensive stuff“ (this technique is called Priming) ▪ In case of DynamoDB client put the following code outside of the handler method to pre-initialize the HTTP Client and Jackson Marshaller: DynamoDbClient client = DynamoDbClientBuilder.builder().region(Regions.US_WEST_2).build(); GetItemResponse getItemResponse = client.getItem(GetItemRequest.builder() .key(Map.of("PK", AttributeValue.builder().s(id).build())) .tableName(PRODUCT_TABLE_NAME).build()); …… Best Practices & Recommendations How to develop, run and optimize Spring Boot 3 application on AWS Lambda 48 invocation forces HTTP Client and Jackson Marshallers to pre-initialize getProductById (int id) method
  • 47.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Enabled with Java Priming High performance Serverless Java on AWS 49 https://dev.to/aws-builders/measuring-java-11-lambda-cold-starts-with-snapstart-part-5-priming-end-to-end-latency-and-deployment-time-jem <dependency> <groupId>io.github.crac</groupId> <artifactId>org-crac</artifactId> <version>0.1.3</version> </dependency> if a refer to Priming in this talk, I mean concretely DynamoDB request invocation priming
  • 48.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda SnapStart Priming Guide High performance Serverless Java on AWS 50 guide aims to explain techniques for priming Java applications. It assumes a base understanding of AWS Lambda, Lambda SnapStart, and CRaC. https://github.com/marksailes/snapstart-priming-guide
  • 49.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 p50 p75 p90 p99 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
  • 50.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0,00 5,00 10,00 15,00 20,00 25,00 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Warm starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client compilation - XX:+TieredCompilation -XX:TieredStopAtLevel=1 p50 p75 p90 p99 https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
  • 51.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 200 400 600 800 1000 1200 1400 1600 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Warm starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client compilation - XX:+TieredCompilation -XX:TieredStopAtLevel=1 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
  • 52.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 54 https://github.com/Vadym79/AWSLambdaJavaSnapStart ▪ Lambda has 1024 MB memory setting ▪ Lambda uses x86 architecture ▪ Default (Apache) Http Client for communication with DynamoDB ▪ 18 MB artifact size, , all dependencies in the POM file ▪ Java compilation option - XX:+TieredCompilation - XX:TieredStopAtLevel=1 ▪ Info about the experiments: ▪ Approx. 1 hour duration ▪ Approx. first* 100 cold starts ▪ Approx. first 100.000 warm starts *after Lambda function being re-deployed
  • 53.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda Memory Setting High performance Serverless Java on AWS 55 ONE SECOND ONE GB
  • 54.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime for different memory settings p90 256 MB 512 MB 768 MB 1024 MB 1536 MB 2048 MB https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
  • 55.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Java Compilation High performance Serverless Java on AWS 66 https://www.geeksforgeeks.org/what-are-the-roles-of-java-compiler-and-interpreter/
  • 56.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Java Compilation Options High performance Serverless Java on AWS 67 Mark Sailes: "Optimizing AWS Lambda function performance for Java” https://aws.amazon.com/de/blogs/compute/optimizing-aws-lambda-function-performance-for-java/
  • 57.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 1000 2000 3000 4000 5000 6000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime using different compilation options for p90 Tiered StopAtLevel 1 StopAtLevel 2 StopAtLevel 3 StopAtLevel 4 https://dev.to/aws-builders/aws-snapstart-part-14-measuring-cold-and-warm-starts-with-java-21-using-different-compilation-options-el4 ms
  • 58.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0,00 2,00 4,00 6,00 8,00 10,00 12,00 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Warm starts of Lambda function with Java 21 runtime using different compilation options for p90 Tiered StopAtLevel 1 StopAtLevel 2 StopAtLevel 3 StopAtLevel 4 https://dev.to/aws-builders/aws-snapstart-part-14-measuring-cold-and-warm-starts-with-java-21-using-different-compilation-options-el4 ms
  • 59.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Java Garbage Collection Algorithms High performance Serverless Java on AWS 70 • Tested with default GC algorithms settings • G1 default GC produces the best results for cold and warm starts without and with SnapStart (and priming) followed by : • Parallel GC • Shenandoah GC • Couldn‘t make it work with ZGC (generational) GC
  • 60.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH JEP 318: Epsilon: A No-Op Garbage Collector (Experimental) High performance Serverless Java on AWS 71 https://openjdk.org/jeps/318
  • 61.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda Architecture High performance Serverless Java on AWS 72 https://www.partitionwizard.com/partitionmanager/arm64-vs-x64.html
  • 62.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda x86_64 vs arm64 architecture High performance Serverless Java on AWS 74 https://aws.amazon.com/lambda/pricing/?nc1=h_ls For the same memory setting Lambda and Lambda function execution duration the choice of arm64 over x86_64 architecture is approx. 25% cheaper
  • 63.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 4500 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Cold starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 for p90 x86_64 arm64 ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2 +8,6% +23,9% +24,8%
  • 64.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 6,40 6,60 6,80 7,00 7,20 7,40 7,60 7,80 8,00 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Warm starts of Lambda function with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 for p90 x86_64 arm64 ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2 +9,1% +10,1% +4,8%
  • 65.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH HTTP Clients to connect to DynamoDB High performance Serverless Java on AWS 77
  • 66.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH DynamoDbClient client = DynamoDbClient.builder().region(Region.EU_CENTRAL_1) . httpClient(ApacheHttpClient.create()) //.httpClient(UrlConnectionHttpClient.create()) //.httpClient(AwsCrtHttpClient.create()) .build(); Add dependency to the synchronous HTTP Client in use to pom.xml, i.e. <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>aws-crt-client</artifactId> </dependency> Setting synchronous DynamoDB Client High performance Serverless Java on AWS 78
  • 67.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Cold starts of Lambda function with Java 21 runtime and StopAtLevel 1 compilation and different synchronous HTTP Clients for p90 URL Connection Apache AWS CRT https://dev.to/aws-builders/aws-snapstart-part-15-measuring-cold-and-warm-starts-with-java-21-using-different-synchronous-http-clients-579o ms
  • 68.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH DynamoDbAsyncClient dynamoAsyncDbClient = DynamoDbAsyncClient.builder().region(Region.EU_CENTRAL_1) . httpClient(NettyNioAsyncHttpClient.create()) //.httpClient(AwsCrtAsyncHttpClient.create()) .build(); CompletableFuture<GetItemResponse> getItemReponseAsync = dynamoAsyncDbClient.getItem(GetItemRequest.builder(). key(Map.of("PK",AttributeValue.builder(). s(id).build())).tableName(PRODUCT_TABLE_NAME).build()); GetItemResponse getItemResponse = getItemReponseAsync.join(); Setting asynchronous DynamoDB Client High performance Serverless Java on AWS 81
  • 69.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Add dependency to the asynchronous HTTP Client in use to pom.xml, i.e. <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>netty-nio-client</artifactId> </dependency> Setting asynchronous DynamoDB Client High performance Serverless Java on AWS 82
  • 70.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Cold starts of Lambda function with Java 21 runtime and StopAtLevel 1 compilation and different asynchronous HTTP Clients for p90 NettyNio AWS CRT ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2
  • 71.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0,00 2,00 4,00 6,00 8,00 10,00 12,00 w/o AWS SnapStart with AWS SnapStart w/o priming with AWS SnapStart with priming Warm starts of Lambda function with Java 21 runtime and StopAtLevel 1 compilation and different asynchronous HTTP Clients for p90 NettyNio AWS CRT ms https://dev.to/aws-builders/aws-snapstart-part-16-measuring-cold-and-warm-starts-with-java-21-using-different-asynchronous-http-clients-4n2
  • 72.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH HTTP client recommendations High performance Serverless Java on AWS 85 https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/http-configuration.html
  • 73.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda Deployment Artifact Size High performance Serverless Java on AWS 86
  • 74.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 4500 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming Cold starts of Lambda function with Java 21 runtime using deployment artifact sizes for p90 p90 small p90 medium p90 big ms https://dev.to/aws-builders/aws-snapstart-part-11-measuring-cold-starts-with-java-21-using-different-deployment-artifact-sizes-4g29 ▪ Small -137 KB (“Hello World”) ▪ Medium – 14 MB (our sample application) ▪ Big -50 MB (our sample application + additional dependencies other to AWS services)
  • 75.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Less (dependencies, classes) is more ▪ Include only required dependencies (e.g. not the whole AWS SDK 2.0 for Java, but the dependencies to the clients to be used in Lambda) ▪ Exclude dependencies, which you don‘t need at runtime i.e. test frameworks like Junit Best Practices & Recommendations High performance Serverless Java on AWS 88 <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.4.2</version> <scope>test</scope> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> <version>2.22.2</version> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.22.2</version> <type>pom</type> <scope>import</scope> </dependency>
  • 76.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Exclude unused HTTP Client dependencies High performance Serverless Java on AWS 89 <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> <exclusions> <exclusion> <groupId>software.amazon.awssdk</groupId> <artifactId>netty-nio-client</artifactId> </exclusion> <!-- <exclusion> <groupId>software.amazon.awssdk</groupId> <artifactId>apache-client</artifactId> </exclusion> --> </exclusions> </dependency>
  • 77.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS CRT HTTP Client High performance Serverless Java on AWS 90
  • 78.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS CRT HTTP Client for Linux High performance Serverless Java on AWS 91 In Linux folder:
  • 79.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Exclude unused AWS CRT HTTP Client platform dependencies High performance Serverless Java on AWS 92 <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>aws-crt-client</artifactId> <exclusions> <exclusion> <groupId>software.amazon.awssdk.crt</groupId> <artifactId>aws-crt</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>software.amazon.awssdk.crt</groupId> <artifactId>aws-crt</artifactId> <classifier>linux-x86_64</classifier> </dependency> https://github.com/awslabs/aws-crt-java?tab=readme-ov-file#platform-specific-jars
  • 80.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Demo Application High performance Serverless Java on AWS 93 https://github.com/Vadym79/AWSLambdaJavaSnapStart ▪ Lambda has 1024 MB memory setting ▪ Lambda uses x86 architecture ▪ Default (Apache) Http Client for communication with DynamoDB ▪ 14 MB artifact size, all dependencies in the POM file ▪ Java compilation option - XX:+TieredCompilation - XX:TieredStopAtLevel=1 ▪ Info about the experiments: ▪ Approx. 1 hour duration ▪ Approx. first* 100 cold starts ▪ Approx. first 100.000 warm starts *after Lambda function being re-deployed
  • 81.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Deployment & Invocation High performance Serverless Java on AWS 94 https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html https://aws.amazon.com/de/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/ Firecracker microVM create & restore snapshot
  • 82.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart tiered cache How to develop, run and optimize Spring Boot 3 application on AWS Lambda 95 https://dev.to/aws-builders/aws-snapstart-part-17-impact-of-the-snapshot-tiered-cache-on-the-cold-starts-with-java-21-52ef • Due to the effect of snapshot tiered cache, cold start times reduces with the number of invocations • After certain number of invocations reached the cold start times becomes stable
  • 83.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda under the Hood High performance Serverless Java on AWS 96 https://www.infoq.com/articles/aws-lambda-under-the-hood/ https://www.infoq.com/presentations/aws-lambda-arch/
  • 84.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 with SnapStart w/o Primingwith SnapStart w/o Priming (last 70) with SnapStart with Priming with SnapStart with Priming (last 70) Cold starts of all approx.100 and last 70 Lambda functions with Java 21 runtime with 1024 MB memory setting, Apache Http Client, compilation -XX:+TieredCompilation -XX:TieredStopAtLevel=1 p50 p75 p90 p99 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-17-impact-of-the-snapshot-tiered-cache-on-the-cold-starts-with-java-21-52ef Due to the effect of snapshot tiered cache, cold start times reduces with the number of invocations ms
  • 85.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda Profiler Extension for Java High performance Serverless Java on AWS 98 https://github.com/aws/aws-lambda-java-libs/tree/main/experimental/aws-lambda-java-profiler
  • 86.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda Implementation High performance Serverless Java on AWS 99
  • 87.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda Profiler Extension for Java High performance Serverless Java on AWS 100 https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format https://github.com/aws/aws-lambda-java-libs/tree/main/experimental/aws-lambda-java-profiler
  • 88.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Full Priming including APIGatewayProxyRequestEvent Deserialization High performance Serverless Java on AWS 101 https://dev.to/aws-heroes/aws-lambda-profiler-extension-for-java-part-2-improving-lambda-performance-with-lambda-snapstart-4p06
  • 89.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Full Priming including APIGatewayProxyRequestEvent High performance Serverless Java on AWS 102 This priming technique leads to approx. 20% reduction of the cold start times vs. DynamoDB request priming alone
  • 90.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS SnapStart Pricing 103 https://aws.amazon.com/lambda/pricing/?nc1=h_ls
  • 91.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ SnapStart supports the Java 11, 17 and 21 (Corretto), Python and .NET managed runtime only ▪ Deployment with SnapStart enabled takes more than 2-2,5 minutes additionally ▪ Snapshot is deleted from cache if Lambda function is not invoked for 14 days ▪ SnapStart currently does not support : ▪ Provisioned concurrency ▪ Amazon Elastic File System (Amazon EFS) ▪ Ephemeral storage greater than 512 MB AWS SnapStart Challenges & Limitations 104 https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
  • 92.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Avoid saving state that depends on uniqueness during initialization ▪ Avoid UUID uniqueSandboxId = UUID.randomUUID() or long envCreationTime = System.currentTimeMillis() im Lambda constructor ▪ Use cryptographically secure pseudorandom number generators ▪ Software that always gets random numbers from /dev/random or /dev/urandom also maintains randomness with SnapStart. ▪ Use java.security.SecureRandom instead of new Random() ▪ Avoid logic relying on time-based caches AWS SnapStart Challenges around uniqueness 105 https://docs.aws.amazon.com/lambda/latest/dg/snapstart-uniqueness.html
  • 93.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda SnapStart Bug Scanner 106 https://github.com/aws/aws-lambda-snapstart-java-rules • Does recognize the usage of: • UUID.randomUUID() • System.currentTimeMillis() • new Random() • Doesn’t recognize the usage of: • LocalDate*, LocalTime, ZonedDateTime APIs • Time-base cache frameworks like Google Guava and ExpiringMap from net.jodah
  • 94.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Perform Priming out of the box without writing the logic on our own ▪ If snapshot not found do regular cold start and create snapshot under the hood ▪ Snapshot creation on first Lambda function invocation instead of during the deployment phase ▪ Regular cold start as long as the snapshot hasn’t been fully taken ▪ Trade off between duration of the deployment phase and several regular bigger cold starts until the snapshot is taken and SnapStart becomes effective (and therefore much shorter cold starts) AWS SnapStart Possible Next Steps High performance Serverless Java on AWS 107 https://dev.to/aws-builders/reducing-cold-starts-on-aws-lambda-with-java-runtime-future-ideas-about-snapstart-graalvm-and-co-3a1b
  • 95.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 108 High performance Serverless Java on AWS
  • 96.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ Low footprint ahead-of-time mode for JVM-based languages ▪ High performance for all languages ▪ Convenient language interoperability and polyglot tooling GraalVM Goals High performance Serverless Java on AWS 109 Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
  • 97.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH GraalVM Architecture High performance Serverless Java on AWS 110
  • 98.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH GraalVM Ahead-of-Time Compilation High performance Serverless Java on AWS 111 Source: Oleg Šelajev, Thomas Wuerthinger, Oracle: “Deep dive into using GraalVM for Java and JavaScript” https://www.youtube.com/watch?v=a-XEZobXspo
  • 99.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AOT vs JIT High performance Serverless Java on AWS 112 Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
  • 100.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Promise: Java Function compiled into a native executable using GraalVM Native Image significantly reduces ▪ “cold start” times ▪ memory footprint GraalVM Native Image 113
  • 101.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ AWS doesn’t provide GraalVM (Native Image) as Java Runtime out of the box ▪ AWS provides Custom Runtime Option Current Challenges with Native Executable using GraalVM High performance Serverless Java on AWS 114
  • 102.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Custom Lambda Runtimes High performance Serverless Java on AWS 115 https://github.com/Vadym79/AWSLambdaGraalVMNativeImage
  • 103.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 500 1000 1500 2000 2500 3000 3500 4000 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming GraalVM 23 Native Image p50 p75 p90 p99 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
  • 104.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0,00 5,00 10,00 15,00 20,00 25,00 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming GraalVM 23 Native Image p50 p75 p90 p99 https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
  • 105.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 200 400 600 800 1000 1200 1400 1600 w/o SnapStart with SnapStart w/o Priming with SnapStart with Priming GraalVM Native Image 23 p99.9 max https://dev.to/aws-builders/aws-snapstart-part-13-measuring-warm-starts-with-java-21-using-different-lambda-memory-settings-160k ms
  • 106.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda Memory Setting for Custom Runtime (GraalVM Native Image) High performance Serverless Java on AWS 121 ONE SECOND ONE GB
  • 107.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 0 200 400 600 800 1000 1200 256 MB 512 MB 768 MB 1024 MB 1280 MB 1536 MB Cold starts of Lambda function with GraalVM 21 Native Image for different memory settings p50 p75 p90 p99 p99.9 max https://github.com/Vadym79/AWSLambdaGraalVMNativeImage/tree/master/pure-lambda-graalvm-jdk-21-native-image ms
  • 108.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Other optimizations 125 AWS CRT Client supports GraalVM Native Image DynamoDbClient client = DynamoDbClient.builder(). region(Region.EU_CENTRAL_1) ..httpClient(AwsCrtHttpClient.create()) .build(); https://aws.amazon.com/de/blogs/developer/aws-crt-client-for-java-adds-graalvm-native-image-support/ https://dev.to/aws-heroes/lambda-function-with-graalvm-native-image-part-6-measuring-cold-and-warm-starts-with-graalvm-23-4d3a
  • 109.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Frameworks and libraries Ready for GraalVM Native Image High performance Serverless Java on AWS 126 https://www.graalvm.org/native-image/libraries-and-frameworks/
  • 110.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ You can run into errors when application is running Complex GraalVM Native Image configuration High performance Serverless Java on AWS 127 https://github.com/Vadym79/AWSLambdaGraalVMNativeImage/blob/master/pure-lambda-graalvm-jdk-21-native-image/src/main/reflect.json
  • 111.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Complex GraalVM Native Image configuration High performance Serverless Java on AWS 128
  • 112.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Particulary logging configuration in GraalVM Native Image is complex High performance Serverless Java on AWS 129
  • 113.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Log4j natively supports GraalVM Native since 2.0.25 High performance Serverless Java on AWS 130 https://logging.staged.apache.org/log4j/2.x/graalvm.html
  • 114.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Assisted Configuration with GraalVM Tracing Agent High performance Serverless Java on AWS 131 https://www.graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/ https://www.graalvm.org/latest/reference-manual/native-image/guides/configure-with-tracing-agent/ Run the GraalVM tracing agent during the execution of your tests
  • 115.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ GraalVM is really powerful and has a lot of potential ▪ GraalVM Native Image improves cold starts and memory footprint significantly ▪ GraalVM Native Image is currently not without challenges ▪ Complex GraalVM Native Image configuration files ▪ AWS Lambda Custom Runtime requires Linux executable only ▪ Building Custom Runtime requires some additional effort ▪ e.g. you need a scalable CI/CD pipeline to build memory-intensive native image ▪ Build time is a factor ▪ You need to carefully test to avoid runtime errors GraalVM Conclusion 132
  • 116.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Lambda Proactive Initialization High performance Serverless Java on AWS 134 In June 2023 AWS updated the documentation for the Lambda Function lifecycle and included this new statement: for functions using unreserved (on-demand) concurrency, Lambda may proactively initialize a function instance, even if there's no invocation. When this happens, you can observe an unexpected time gap between your function's initialization and invocation phases. This gap can appear similar to what you would observe when using provisioned concurrency. https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html https://aaronstuyvenberg.com/posts/understanding-proactive-initialization Running this query over several days across multiple runtimes and invocation methods, between 50% and 75% of initializations were proactive (versus 50% to 25% which were true cold starts)
  • 117.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Database Choice DynamoDB Aurora Aurora Serverless vs vs
  • 118.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea DynamoDB DynamoDB + DAX Investment in Knowledge • Understanding of NoSQL databases • Understanding of single-table design principles Same Requires to put Lambda into the VPC to access the database DynamoDB
  • 119.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea Aurora (Serverless v2) + RDS Proxy Aurora (Serverless v2) + Data API Investment in Knowledge Relational databases are familiar to many developers Same Engine Support MySQL and PostgreSQL MySQL and PostgreSQL Code re-use Yes, only endpoint changes No, requires code re-write Requires to put Lambda into the VPC to access the database https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.Aurora_Fea_Regions_DB-eng.Feature.ServerlessV2.html https://dev.to/aws-builders/data-api-for-amazon-aurora-serverless-v2-with-aws-sdk-for-java-part-1-introduction-and-set-up-of-the-sample-application-3g71 Aurora (Serverless v2 )
  • 120.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH “Data API for Amazon Aurora Serverless v2 with AWS SDK for Java” series High performance Serverless Java on AWS 139 Article series also covers cold and warm start time measurements and optimization techniques https://dev.to/vkazulkin/series/26067
  • 121.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Database Choice DynamoDB Aurora Aurora Serverless vs vs vs Aurora DSQL
  • 122.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea • Amazon Aurora DSQL the fastest serverless distributed SQL database • It offers virtually unlimited scale, highest availability, and zero infrastructure management. • It can scale to meet any workload demand without database sharding operational burden of patching, upgrades, maintenance downtime, and more. • With its active-active distributed architecture, Aurora DSQL is designed for 99.99% availability in single-Region configuration and 99.999% in multi-Region configuration, with an innovative active-active, distributed architecture Adding Aurora DSQL into the mix https://aws.amazon.com/blogs/database/introducing-amazon-aurora-dsql/
  • 123.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Unsupported PostgreSQL features in Aurora DSQL High performance Serverless Java on AWS 142 https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-unsupported-features.html
  • 124.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH AWS Lambda with Java managed runtime and Aurora DSQL as a database High performance Serverless Java on AWS 143 ▪ First example using PgJDBC and Hikari datasource pool commited ▪ Lambda performance measurements with/without SnapStart and priming and GraalVM Native Image will follow ▪ With pure Java JDBC API and ORM framework like Hibernate ▪ With single and multi-region Aurora DSQL cluster ▪ Article series with step by step instructions will follow as well https://github.com/Vadym79/AWSLambdaJavaWithAmazonDSQL/tree/main
  • 125.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Experiment with: ▪ Lambda memory settings ▪ Java compilation options ▪ HTTP Client implementations (sync and async) ▪ Lambda architecture ▪ Lambda SnapStart (with priming techniques) and GraalVM Native Image To find the right trade-off between Lambda cost and performance for your particular use case Wrap up How to develop, run and optimize Spring Boot 3 application on AWS Lambda 145
  • 126.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH ▪ With AWS SnapStart and GraalVM Native Image you can reduce cold start times of the AWS Lambda with Java 21 runtime to the acceptable values ▪ If you’re willing to accept slightly higher cold and warm start times for certain the Lambda function(s) and solid priming is applicable -> use fully managed AWS SnapStart with priming ▪ If a very high performance for certain the Lambda function(s) is really crucial for your business -> go for GraalVM Native Image Wrap up and personal suggestions How to develop, run and optimize Spring Boot 3 application on AWS Lambda 146
  • 127.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Project Leyden High performance Serverless Java on AWS 147 The primary goal of this Project is to improve the startup time, time to peak performance, and footprint of Java programs. https://www.youtube.com/watch?v=teXijm79vno https://openjdk.org/projects/leyden/
  • 128.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH Word of caution High performance Serverless Java on AWS 148 Re-measure for your use case! Even with my examples measurements might already produce different results due to: ▪ Lambda Amazon Corretto Java 21 managed runtime minor version changes ▪ Lambda SnapStart snapshot create and restore improvements ▪ Firecracker VM improvements ▪ GraalVM (major and minor version) and Native Image improvements ▪ There are still servers behind Lambda ▪ Java Memory Model impact (L or RAM caches hits and misses)
  • 129.
    Vadym Kazulkin |@VKazulkin |ip.labs GmbH 149 High performance Serverless Java on AWS Thank you